Getting only direct child pages in WordPress with get_pages

I am trying to fetch all direct children of a page. But I am getting all children and grand children as well. Any ideas? PHP Source: $args = array( 'child_of' => $post->ID, 'parent ' => $post->ID, 'hierarchical' => 0, 'sort_column' => 'menu_order', 'sort_order' => 'asc' ); $mypages = get_pages( $args ); foreach( $mypages as $post ) { $post_tempalte = the_page_template_part(); get_template_part( 'content' , $post_tempalte ); } My $args should be correct according to the documentation, but it's totally ignoring parent …
Category: Web

How to get the value of input hidden html from text editor to custom page template?

I have 10 or more input hidden in 10 or more pages with different values in Wordpress text editor and I want to get the value using $_POST in a custom page template. How to do this? I tried to called the input hidden name in my custom page template but the value is not getting. Text editor <form method="POST"> <input type="hidden" name="segment" value="test"/> </form> Custom page template $segment = isset($_POST['segment']) ? $_POST['segment'] : '';
Category: Web

Full width layout for custom post type pages

I'm trying to remove a widget area called 'Primary' from a certain page on a site. This is the function where I manage the sidebars: //ADD CATEGORIES IN SIDEBAR OF SINGLE POST TYPE add_action( 'genesis_sidebar', 'add_mysite_sidebar' ); function add_mysite_sidebar() { if( get_post_type() == 'post' ){ dynamic_sidebar( 'News Categories' ); } else if( get_post_type() == 'events' ){ dynamic_sidebar( 'Event Categories' ); } else if( get_post_type() == 'documentlibrary' ){ dynamic_sidebar( 'Document Categories' ); } else if( get_post_type() == 'bp_members' ){ include(members_sidebar.php); unregister_sidebar( …
Category: Web

RSS feed for a custom page template

I would like to know if it is possible to have a custom feed based on a page template and how? This is my custom query: $my_custom_query = new WP_Query( array('cat' => array (4335, 12488), 'posts_type' => 'post', 'showposts' => 35, 'paged' => $paged, 'meta_key' => 'views', 'orderby'=> 'meta_value', 'order' => 'desc', //'orderby' => 'desc', // BOF EXCLUDES POSTS YOUNGER THEN TODAY -30 DAYS * 'date_query' => array( 'column' => 'post_date', //'after' => '2010-01-01', //'before' => date('Y-m-d', strtotime('-30 days')) ), …
Category: Web

Pagination stopped working after assigning custom page template to new page (different slug)

I am having a problem with pagination on one of my CPT after assigning the custom page template to a different page with a different slug. It all worked perfectly on the test page I developed it with. Only after the new assignment did I run into this issue for subsequent pages (2,3,etc.). Page 1 still works fine. I did resave the Permalinks in WP after the assignment of the custom page template and cleared and rebuild all caches (WP …
Category: Web

Create Dynamic SEO Friendly URL for Virtual Page

I have a Wordpress site that is built to be a job listing board, and I'm looking to create SEO friendly URLs based on data that is stored in the database. The URL structure should include the state abbreviation, city, and job title, and result in the following format: www.domain.com/job/ca/sacramento/janitor There is currently a "Job" page in the backend that uses custom page template located at 'page-templages/job-template.php' that displays the database information at the following URL: www.domain.com/job/?2020-412341235134 How can I …
Category: Web

Redirect based on referer using Advanced Custom Fields

Im currently trying to protect some WP pages by assigning a specific template to them. Ive created the ACF fields "Referring URL" and "Redirect URL", as these could alter depending which page the template is assigned to. What changes would be needed to have the template functionality go: IF referer is not "referring_url" redirect to "redirect_url" Id like there to be no caching taking place either However, the code below, placed just below get_header();, doesn't seem to work consistently, either …
Category: Web

Display images in template file

I have one template file for the main page, after creating home page I have added text to check if it reflect changes on my home page or not and it was successfully displaying text. But when I try to add image by clicking on add media option then image is uploaded but not displaying on my page. What piece of code should be used to get this image on my template file or any other suggestions?
Category: Web

How to duplicate a page template but make minor changes to the header?

I will apologize in advance, I am very new to this. I have been teaching myself php as a hobby, but now I need it for work! I don't work as a web designer, but to try and save some money, I need to be able to make minor changes to our website. I can handle most things... But this one issue is throwing me for a loop. The page was designed by a "marketing firm" and the code is …
Category: Web

How to create a shortcode for custom page template

I have a custom page template and I want it to display on specific pages. The only way I know to do this is to create a shortcode for this custom page template, so that I can use the custom page template by using shortcode. But I don't know how doing this. I saw some article about this, but I forgot the website link. How to create a shortcode for custom page template?
Category: Web

Custom Header added within Dashboard pages, is this possible with custom template files?

I created a custom template and called it Header Home"header-home.php" <?php /** * Template Name: Header Home */ ?> <?php if( have_post() ) { while( have_post() ){ the_post(); } } ?> Then on my front page i call it with <?php get_header( 'home' ); ?> Now, when i create a page, and use template "Header Home" and add my html content inside, it's not showing on the front page at all. Shouldn't the loop grab those html and add it …
Category: Web

show a specific metabox dependent on the page template

For a few days I am trying to show a specific metabox dependent on the page template. I can do it but my problem is when I have selected a page template and hit the update button then the metabox does not show. metabox is showing when I reload the page. Actually, I want when I will hit the update button then the metabox will be shown. please help me. Note: I use CMB2 for meta boxes. I tried this …
Category: Web

No templates for condition page.php Elementor

I am building a WordPress theme and I want it to support the Elementor theme. But I get this error in Elementor Debugging mode. No Template for condition > theme name -page.php What could be the cause? This my page.php <?php get_header(); ?> <?php if ( have_posts() ) { while ( have_posts() ) { the_post(); the_title( ); the_content(); } // end while } // end if ?> <?php get_footer();
Category: Web

Show index.php template instead of 404 page template

I have some posts that were permanently deleted, however, instead of wordpress returning the 404.php page template, it is returning the index.php template. In other posts, the behavior is right, but in some like this it is not What I've done so far: theme change to twenty-two I updated the permalink structure I cleaned the database with the advanced database cleaner plugin. There is no cache However, nothing resolved. You can see below the template shown and the correct status …
Category: Web

How to move page template files like page-{slug}.php to a sub-directory?

I want to move page template files like page-{slug}.php to a sub-directory within my theme, in a way that WordPress will recognize them automatically. If the page templates of the said form doesn't exist within the sub-directory, then WordPress should fall back to the default template loading rules. How can I achieve that? Note-1: This question and corresponding answers are more generic for page templates and this link mentions template-parts/page, which is not the same thing. Note-2: I have multiple …
Category: Web

Using URL variables on a custom WP_Query

Background I have a page with a custom template 'listen', with a custom wp_query running on it... $custom_query_args = array( 'post_type' => 'post', 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-audio' ), ), ), ); The Problem When I try and filter the posts on this page with url variables (example.com/listen/?category_name=thebigshow), nothing changes, even if I spell the category name incorrectly. How can I use this method to filter the 'listen' page, by 'category_name' …
Category: Web

Pagination on a custom page template

I have set up a custom post type called 'Events'. For reasons that I'm not going to get into, I chose not use archive-events.php as the archive template for my Events. Instead, I decided to create a custom page template, page-upcoming-events.php, to use as an archive. I wrote a custom query in this template to pull in events. I am also limiting posts_per_page to 4. I've successfully added pagination links using the previous_posts_link() and next_posts_link() functions. These functions are generating …
Category: Web

How to use custom footer template in a site-plugin?

I have a site-plugin to centralize most of the theme customization. I want to override the default footer.php template with a customfooter.php (removes the Proudly Powered by WordPress) stored inside the /plugins directory structure. I found this resource on StackExchange, one here, and tried some. Obviously, I am making errors. Could someone please advise how to achieve this without touching the theme files / directories? add_filter( 'theme_page_templates', 'force_customization', 101 ); function force_customization( $newtemplate ) { if ( is_singular( 'footer' ) …
Category: Web

Restrict Access to Logged-In Users Page Template

I am trying to create a page template that restricts content to only logged-in users, if they are not logged in then they are re-directed to a specific page. I have created a page template called Restrict Access. Here is the code that I came up with, I have tried many times to put this snippet in the page.php below and it still shows the content. Can someone please help me and put this in where it is supposed to …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.