Post types by taxonomy

Asked

Viewed 233 times

0

I’m doing it this way and yet, it’s not pulling taxonomy that I want. It’s pulling standard WP posts and not mine specifically.

My post type is the 'post_type' => 'posts_blog', as below and the taxonomy of this post is the categ_blog_home, and in this taxonomy I have the old posts_there and even passing code below, I can not pull it.

                <?php 
                    $args = array(
                        'post_type' => 'posts_blog',
                        'status' => 'publish',
                        'numberpost' => 4,

                        'tax_query' => array(
                            'taxonomy' => 'categ',
                            'terms' => 'posts-testes',
                        )
                    );
                    $query = new WP_Query( $args );
                 ?>

                <?php 
                    if (have_posts()) : 
                        foreach( $query as $post ) : setup_postdata ( $post );?>     
                            <div class="all-posts-antigos">

                                <div class="block-thumb">
                                    <?php the_post_thumbnail(); ?>
                                </div>

                                <div class="block-infos">
                                    <h1><?php the_title(); ?></h1>
                                    <h3><?php the_author_posts_link(); ?></h3>
                                    <span><?php the_time("d/m/Y"); ?></span>
                                    <p><?php the_content(); ?></p>
                                    <?php get_taxonomies( $args, $output, $operator ) ?>
                                </div>

                            </div>
                        <?php  
                    endforeach; 
                    else:
                        echo '<p class="bg-warning">Nenhum post foi encontrado.</p>';
                endif; ?>
            </div>>

1 answer

0

There are some errors in your code, try the fixes below:

                <?php 
                $args = array(
                    'post_type' => 'posts_blog',
                    'status' => 'publish',
                    'numberpost' => 4,

                    'tax_query' => array(
                        'taxonomy' => 'categ',
                        'terms' => 'posts-testes',
                    )
                );
                $query = new WP_Query( $args );
             ?>

            <?php 
                if ($query->have_posts()) : 
                    while ($query->have_posts()) : $query->the_post();?>     
                        <div class="all-posts-antigos">

                            <div class="block-thumb">
                                <?php the_post_thumbnail(); ?>
                            </div>

                            <div class="block-infos">
                                <h1><?php the_title(); ?></h1>
                                <h3><?php the_author_posts_link(); ?></h3>
                                <span><?php the_time("d/m/Y"); ?></span>
                                <p><?php the_content(); ?></p>
                            </div>

                        </div>
                    <?php  
                    endwhile; 
                else:
                    echo '<p class="bg-warning">Nenhum post foi encontrado.</p>';
                endif; 
                wp_reset_postdata();
            ?>
        </div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.