简体   繁体   中英

list of all post from the current taxonomy of custom post type

I am creating custom post type(cpt) called circular . and the taxonomy for the cpt is circular_category in wordpress

What I want to achieve is generate a list of the titles of all circular custom post type in current taxonomy page. the permalink /circular_category/free-circular/

I tried with this code with no luck, any ideas? Here are some variable that can be add to the query

$cir_cat   = $wp_query->get_queried_object();
$cat_name  = $cir_cat->name;
$cat_id    = $cir_cat->term_id;
$cat_slug  = $cir_cat->slug ;

The Query

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
    'post_type' => 'circular',
    'posts_per_page' => -1,
    'order' => 'DESC',
    'orderby' => 'post_title',
    'category__in' => $cat_id,
    'paged' => $paged,
    'tax_query' => array(
        array(
            'taxonomy' => 'circular_category',
        )
    )
);
$circular_query = new WP_Query( $args );

Now display the list cpt post from current cpt category

<ul id="circulars">
<?php
if($circular_query->have_posts()) :
    while($circular_query->have_posts())  : $circular_query->the_post();
    ?>
        <li>
            <a href="<?php the_permalink() ?>" title="Link to <?php the_title_attribute() ?>">
             <?php get_the_title(); ?> 
            </a>
        </li>           
    <?php endwhile; ?>
        </ul> 
    <?php 

    $total_pages = $circular_query->max_num_pages;
    if ($total_pages > 1){
        $current_page = max(1, get_query_var('paged'));
        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => '/pages/%#%',
            'current' => $current_page,
            'total' => $total_pages,
            'prev_text'    => __('« prev'),
            'next_text'    => __('next »'),
        ));
    }
    ?>    
<?php else :?>
<h3><?php _e('No Circular found', ''); ?></h3>

<?php endif; ?>
<?php wp_reset_postdata();?>

I have changed the query and its works I'm giving the answer here if someone needed

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
    'post_type' => 'circular',
    'posts_per_page' => -1,
    'order' => 'DESC',
    'orderby' => 'post_title',
    'paged' => $paged,
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'circular_category',
            'field' => 'slug',
            'terms' => $cat_slug
        )
     ),

);
$circular_query = new WP_Query( $args );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM