Answer the question
In order to leave comments, you need to log in
How to display buttons in Wordpress with links to pages using a specific template?
C created a new page-new.php file with /* Template Name: template name */ and defined this template for some pages. And I want to display on each page that uses this template, links and headings in the buttons on each page that uses this template. (I apologize for the tautology, but it's probably clearer this way).
How to do it?
Answer the question
In order to leave comments, you need to log in
The template used (the file, not its name) is recorded in wp_postmeta, you can get it using meta_query:
$args = [
'post_type' => 'page',
'posts_per_page' => 100,
// 'post__not_in' => [ get_the_ID() ], // Раскомментируйте, если хотите исключить текущую страницу
'meta_query' => [
[
'key' => '_wp_page_template',
'value' => 'custom-template.php'
]
]
];
$my_pages = new WP_Query( $args );
if ( $my_pages->have_posts() ) :
while ( $my_pages->have_posts() ) : $my_pages->the_post();
the_title( '<h3>', '</h3>' );
endwhile;
endif;
wp_reset_postdata();
Use WP_Query with
'meta_key' => '_wp_page_template',
'meta_value' => 'my_template.php'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question