0

I am trying to query some posts by the category slug (and parent post category slug)

I can get the slug using

<?php echo $post->post_name; ?>

or

<?php $post_data = get_post($post->post_parent);
$parent_slug = $post_data->post_name;
echo $parent_slug; ?>

I would like to insert that into the query below:

<?php $query = new WP_Query(array(
'post_type' => 'offers',
'category_name' => 'PAGE-SLUG-event'
)); ?>

So effectively I am trying to do this, which doesn't obviously work.

 <?php $query = new WP_Query(array(
 'post_type' => 'offers',
 'category_name' => '<?php echo $post->post_name; ?>-event'
 )); ?>
1
  • 'category_name' => $post->post_name . '-event' is the correct way to pass that slug appended with -event.
    – Sally CJ
    Commented Mar 11, 2020 at 15:54

1 Answer 1

0

function namefunctions(){ $args = array( 'post_type' => 'CPT', 'posts_per_page' => -1, ); $recetax = new wp_query($args); while ( $recetax->have_posts()): $recetax->the_post(); ?>

/* your content of ctp*/

<?php endwhile; wp_reset_query();  

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.