Home › Forums › Front-end Issues › Query posts from custom post-type and taxonomy
Hi basically I made a loop page but i just want to query posts from my custom posts type called “videos” then i have a custom post taxonomy along with “videos” called “topics”
<?php
$customPost_type = 'videos';
$taxonomyValue = get_field('loop_select_video');
$taxonomyVideoNum = get_field('loop_number_of_videos');
if($taxonomyValue){
$args=array(
'taxonomy' => $taxonomyValue,
'post_type' => $customPost_type,
'posts_per_page'=> $taxonomyVideoNum, // Number of related posts to display
'order'=>'DESC' //query desc posts
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<article class="art-article art-video">
<?php if(get_field('video_code')) { ?>
<div class="art-article-video">
<?php echo do_shortcode('
['. get_field('video_type') .' id="'. get_field('video_code') . '"]
');?>
</div>
<?php } ?>
<div class="art-article-desc alpha">
<a href="#" title="<?php the_title(); ?>">
<h2><?php the_title(); ?></h2>
</a>
<?php if(get_field('video_code')) { ?>
<p><?php echo get_field('video_description');?></p>
<?php } ?>
</div>
</article>
<?php
}
wp_reset_query();
}else{ //if no tag is selected
echo("no Tag is selected in the Taxonomy Dropdown menu");
}
?>
<!-- LOOP -->
</div>
In my page editor, there is a select box contains contents from topics (means categories of videos)..
that when i tick one of them, it should loop according from what i selected.. but in my case it doesnt .. by the way it has a hierarchy.
– Topic
– type a
– type b
– type c
– type d
if i want to select the type a , the loop should only show posts from type a . same with type b ,type c , and type d.. then If i select the parent “Topic” it should show all.. My was if i select the children they doesnt work but the parent works.. please help me.
hierarchy correction :
– Topic
* Type a
* Type b
* Type c
* Type d
Hi @slash_1968
Just to clarify. Your question is how to get your WP_Query behaving correctly?
Lets first start by debugging the code. Perhaps you could print out the $args array. What does it look like? Does it look correct?
Then, print out the $my_query object. You will see a section of the object contains the actual SQL which is run. Does this look correct?
Please research up on the WP_Query object before posting back if you don’t understand some of the above.
Thanks
E
Hi @elliot,
sorry for the confusion.. i was trying to loop a post by terms under taxonomy.
Post type: Video
taxonomy: Topics
terms under topics:
– Videos
* Video type 1 (sub)
* Video type 1 (sub)
* Video type 1 (sub)
* Video type 1 (sub)
Hi @slash_1968
I don’t understand your last comment. Can you please provide a clear and easy to understand question?
Thanks
E
The topic ‘Query posts from custom post-type and taxonomy’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.