0
    <?php 
get_header();
?>
<?php

//Define the function

function customize_customtaxonomy_archive_display ( $query ) {
    if (($query->is_main_query()) && (is_tax('employee')))

    $query->set( 'posts_per_page', '3' );
    $query->set( 'orderby', 'title' );
    $query->set( 'order', 'ASC' );
}

//Hook the function

add_action( 'pre_get_posts', 'customize_customtaxonomy_archive_display' );

/**
 * @todo filtering on gov_categorie
 */

?>
<section class="content">
    <div class="wrapper">
        <div class="split-block sidebar-right">
            <div class="main-content" data-animation="fadeInUpSmall">
                <h1>Garderense Ondernemers Vereniging</h1>
                <?php 
                    $loop = new WP_Query(array(
                        'paged'          => get_query_var('paged'),
                        'post_type'      => 'gov_members',
                        'posts_per_page' => 20,
                        'tax_query'      => array(
                            // Note: tax_query expects an array of arrays!
                            array(
                                'taxonomy' => 'gov_categorie', // my guess
                                'field'    => 'name',
                            ),
                        ),
                    ));
                ?>
                <div class="gov-wrapper">
                    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
                        <div class="gov-block">
                            <a href="<?php echo the_permalink()?>">
                                <h3><?php the_title();?></h3>
                                <p>
                                    <?php echo esc_html(get_post_meta( get_the_ID(), 'gov_address', true)); ?><br />
                                    <?php echo esc_html(get_post_meta( get_the_ID(), 'gov_postal_city', true)); ?><br />
                                    <?php echo esc_html(get_post_meta( get_the_ID(), 'gov_phone', true)); ?><br />
                                </p>
                            </a>
                        </div>
                    <?php endwhile; ?>
                </div>
            </div>
            <aside id="sidebar">
                <?php while ( $loop->have_posts() ) : $loop->the_post();
                    the_terms( $post->ID, 'gov_categorie' ,  ' ' );
                endwhile; ?>
            </aside>
        </div>
    </div>
</section>
<?php 
get_footer();
?>

With the code above i get none results.

When i delete the tax_query i get all the results how can i change that piece of code to filter on a selected taxonomy.


I've changed it but still no results..., I'm trying this with a custom post type and a custom taxonomy. Also i'm doing this within a custom made plugin. so maybe i'm doing something wrong in another file, because when i make a taxonomy-gov_categorie.php the pages won't find it.

  • Change order by 'title' to 'post_title' – Abhisek Malakar Feb 24 '15 at 8:10
  • Please use comments or edit your question to elaborate. Answers aren't meant for it. – Rarst Feb 24 '15 at 13:46
0

You did not specify a taxonomy term in tax_query. It should go:

'tax_query'      => array(
   array(
    'taxonomy' => 'taxonomy_name', // my guess
    'field'    => 'name',
    'term'     => 'Term name'
   ),
 ),

I prefer using 'field'=>'slug' in such cases as term names are more likely to be changed.

And also change order by 'title' to 'post_title'as Abhisek mentioned in the comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.