最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Why is my loop not populating the page with my custom taxonomy terms from my custom post type?

matteradmin10PV0评论

Why is my loop not populating the page with my custom taxonomy terms from my custom post type? Currently it is displaying an empty box instead of pulling in the custom taxonomy terms from my custom post type series. I am at a complete loss as to why this is. Any assistance that could be provided would be much appreciated!

<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

    $args = array(
        'posts_per_page' => 10,
        'paged' => $paged,
        'taxonomy'=> 'series',
        'field' => 'slug',
        'orderby'    => 'ID', 
        'order'      => 'DESC'
    );

    $custom_query = new WP_Query( $args );
    if ( have_posts() ) : while($custom_query->have_posts()) : $custom_query->the_post(); ?>



        <div class="block_item article">
            <div  class="article_image" style="background: url('<?php the_field('series_artwork', $term); ?>'); background-size: cover; background-position: 50%;"></div>
            <h4 class="section_label"><?php the_field('date', $term); ?></h4>
            <div class="block_item_content">
                <h3><?php echo $term->name; ?></h3>
                <p><?php echo $term->description; ?></p>
                <a href="<?php echo get_term_link($term->slug, 'series'); ?>" class="button_styling">
                    Read More
                </a>
            </div>
        </div>

<?PHP endwhile; endif; ?>


<div class="clear"></div>

<?php // Pagination
if (function_exists("pagination")) {
    pagination($custom_query->max_num_pages);
} ?>

Why is my loop not populating the page with my custom taxonomy terms from my custom post type? Currently it is displaying an empty box instead of pulling in the custom taxonomy terms from my custom post type series. I am at a complete loss as to why this is. Any assistance that could be provided would be much appreciated!

<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

    $args = array(
        'posts_per_page' => 10,
        'paged' => $paged,
        'taxonomy'=> 'series',
        'field' => 'slug',
        'orderby'    => 'ID', 
        'order'      => 'DESC'
    );

    $custom_query = new WP_Query( $args );
    if ( have_posts() ) : while($custom_query->have_posts()) : $custom_query->the_post(); ?>



        <div class="block_item article">
            <div  class="article_image" style="background: url('<?php the_field('series_artwork', $term); ?>'); background-size: cover; background-position: 50%;"></div>
            <h4 class="section_label"><?php the_field('date', $term); ?></h4>
            <div class="block_item_content">
                <h3><?php echo $term->name; ?></h3>
                <p><?php echo $term->description; ?></p>
                <a href="<?php echo get_term_link($term->slug, 'series'); ?>" class="button_styling">
                    Read More
                </a>
            </div>
        </div>

<?PHP endwhile; endif; ?>


<div class="clear"></div>

<?php // Pagination
if (function_exists("pagination")) {
    pagination($custom_query->max_num_pages);
} ?>
Share Improve this question asked Oct 23, 2018 at 20:10 PeterPeter 1351 silver badge10 bronze badges 1
  • 1 Taxonomies aren't posts. Instead of using WP_Query you'll need to use a function to get taxonomy terms instead. – WebElaine Commented Oct 23, 2018 at 20:19
Add a comment  | 

1 Answer 1

Reset to default 0

You need to specify the post type in argument and need to use the taxonomy tag properly. You can try the following args variable.

$args = array(
        'posts_per_page' => 10,
        'post_type' => 'series', //Specify the post type here
        'paged' => $paged,
        'tax_query' => array(
            array(
                'taxonomy'  => '', //specify the taxonomy name
                'field'     => 'slug',
                'terms'     => '', //Specify the slug of what you want from the taxonomy
                'operator'  => 'IN',
            )
        )
        'orderby'    => 'ID', 
        'order'      => 'DESC'
    );
Post a comment

comment list (0)

  1. No comments so far