query_posts, get the category and subcategory

1

Good morning, everyone. For the first time I come to ask for help, after many attempts (I am a beginner).

I'm wanting to list multiple posts (post_type called = family_fish) by category and subcategory. (I'm trying to take advantage of a loop that is working on another page, which shows every post.)

<?php query_posts('familia_peixe_familia=familia_ordem_peixe & showposts= -1 & orderby=title');?>       
                            <?php if (have_posts()): while(have_posts()) : the_post();?>

                                <div id="box-categoria-ficha-peixe-conteudo">
                                    <div class="box-categoria-ficha-peixe-conteudo-faixa">                          

                                            <div class="h3-ficha-peixe-22"><?php if (get_post_meta($post->ID, 'classificacao_peixe_ordem', true)):?><a href="<?php  $key="classificacao_peixe_ordem";echo get_post_meta($post->ID, $key, true);?>" title="<?php echo get_post_meta( $post->ID, 'familia_peixe_ordem', true ); ?>" >Lista ordem dos :  <?php if (get_post_meta($post->ID, 'classificacao_peixe_ordem', true)){echo get_post_meta( $post->ID, 'classificacao_peixe_ordem', true );} ?></a><?php endif?></div>


                                    </div>
                                        <div class="box-categoria-ficha-peixe-conteudo-titulo"><?php the_title();?></div>
                                        <div class="box-categoria-ficha-peixe-conteudo-texto">  <?php echo excerpt(80); ?>

                                    </div>

                            <?php endwhile; else:?>
                            <?php endif;?>

This is what I intended

    
asked by anonymous 06.06.2017 / 12:29

1 answer

1

You did not say what error you are having, but I suppose you should be receiving no results, right? Your current code is specifying the familia_peixe_familia and familia_ordem_peixe taxonomy but does not specify post_type , then query_posts() is looking for type Post .

Rewriting without using query_posts () because using query_posts is never a good idea :

<?php 
$consulta = new WP_Query( array ( 
    'post_type' => 'familia_peixe',
    'posts_per_page' => 100, // use 100 ao invés de -1 para evitar problemas futuros
    'tax_query' => array( array(
        'taxonomy' => 'familia_peixe_familia', // taxonomia
        'term' => 'familia_ordem_peixe', // termo
        'field' => 'slug',
    ) ),
    'orderby' => 'title',
) );

if ( $consulta->have_posts()): while( $consulta->have_posts()) : $consulta->the_post(); ?>
    
06.06.2017 / 14:10