Home Forums Front-end Issues Query posts from custom post-type and taxonomy


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”

           $customPost_type = 'videos';
           $taxonomyValue = get_field('loop_select_video');
           $taxonomyVideoNum = get_field('loop_number_of_videos');
             '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() ) {
           <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') . '"]
            <?php } ?>
            <div class="art-article-desc alpha">
             <a href="#" title="<?php the_title(); ?>">
              <h2><?php the_title(); ?></h2>
             <?php if(get_field('video_code')) { ?>
             <p><?php echo get_field('video_description');?></p>
             <?php } ?>
           }else{ //if no tag is selected
           echo("no Tag is selected in the Taxonomy Dropdown menu");
           <!-- LOOP -->

    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.


  • 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?


Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Query posts from custom post-type and taxonomy’ is closed to new replies.