• Hi,
    I had a custom query for post type to show up posts by tag in a category page (and sub-category pages)

    <?php
    
    // The Query
    $the_query = new WP_Query( 'post_type=video&tag=space' );
    
    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    
    ?>

    But since I’m using this query all posts are showing up in parent category and children categories without caring about the category they belong.

    Before I had `<?php

    if (have_posts()) : while (have_posts()) : the_post();

    ?>` and it was working fine.

    How can I accomplish what I’d like to?

Viewing 1 replies (of 1 total)
  • Thread Starter jumust

    (@jumust)

    I think I have explained very bad. I’ll try again

    – Post Type: Video
    – Custom post “video” with tag”space”
    – Parent category: VideoPage (id=4)
    – Children categories: A-B-C

    I want show for Parent Category and children only custom post type “video” with tag “space”

    In my file category.php I called the template:

    <?php
    	// If is category or subcategory of $cat_id
    if (!function_exists('is_category_or_sub')) {
    	function is_category_or_sub($cat_id = 4) {
    	    foreach (get_the_category() as $cat) {
    	    	if ($cat_id == $cat->cat_ID || cat_is_ancestor_of($cat_id, $cat)) return true;
    	    }
    	    return false;
    	}
    }
    ?>
    
    			<?php if (is_category_or_sub(4)) : ?> 
    
    				<?php load_template(TEMPLATEPATH . '/cat_videopagine.php'); ?>
    
    			<?php else : ?>

    Then in the file cat_videopagine.php I have this:

    <?php
    
    // The Query
    $the_query = new WP_Query( 'post_type=video&tag=space' );
    
    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    
    ?>

    The Problem is:
    Either in parent cat page or all children cat pages all same custom posts “video” with the tag “space”are displayed so I have
    Parent: p1-p2-p3-p4-p5-p6
    Cat A: p1-p2-p3-p4-p5-p6
    Cat B: p1-p2-p3-p4-p5-p6
    Cat C:p1-p2-p3-p4-p5-p6

    There should be a function that calls the category and displays only the posts that belong to those category.
    Cat A : p1(catA)
    Cat B: p3(catB)

Viewing 1 replies (of 1 total)
  • The topic ‘new wp query by tag, it's not showing category post related’ is closed to new replies.