admin管理员组文章数量:1391960
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'
)); ?>
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'
)); ?>
Share
Improve this question
asked Mar 11, 2020 at 15:41
A RimbaudA Rimbaud
1
1
|
1 Answer
Reset to default 0function 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();
}
本文标签: Wordpress Query by Category using Post Slug
版权声明:本文标题:Wordpress Query by Category using Post Slug 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744678641a2619262.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
'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