List a page which has the same title like current post's meta value
-
Hello,
I am trying to list one page (the recent one) which has the same TITLE like the current post META VALUE.
I have come up with the following code, however it is not showing the correct page. Can you please help?
<?php $pagetitle = get_post_meta($post->ID, 'car_model_range', TRUE); $args=array( 'post_type' => 'page', 'post_status' => 'publish', 'post_title' => $pagetitle, 'order'=>'ASC', 'orderby'=>'date', 'posts_per_page' => 1, ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php get_template_part( 'partials/caritem', 'page' ); ?> <?php endwhile; } ?>
Example: there is a page with title “The best page ever” and then I have a post with key car_model_range = “The best page ever”. I want to see on that post also the page that has this title.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘List a page which has the same title like current post's meta value’ is closed to new replies.