0

I have a custom post type “building”, another called “architects” and a custom taxonomy “date” associated to buildings. The taxonomy basically is the year in which the building was finished and buildings and architects are related to one another in the sense that architects make the buildings.

What I want to achieve is run a wp_query that will get all the buildings by a certain architect and sort them by date.

I have achieved the first part were I get all buildings by a certain architect but I cant figure out how to sort them by a custom taxonomy. I’ve read Otto’s answer here Using wp_query is it possible to orderby taxonomy? on how sorting by taxonomy doesn’t make sense, but I believe in my case it does.

This is the code I’m using to get all buildings by a certain architect.

$buildings = new WP_Query(array(
    'post_type' => 'building',
    'posts_per_page' => -1,
    'suppress_filters' => 0,
    'meta_query' => array(
        array(
            'key' => 'architect',
            'value' => '"'.$architect_id.'"',
            'compare' => 'LIKE'
        )
    ),
    'post_status'   => 'publish'
));
5
  • Why are you storing dates as taxonomy? Commented Jul 19, 2018 at 11:01
  • @KrzysiekDróżdż That decision was made a long time ago, it made sense back then... it doesent seem entirely wrong to me either... how would you choose to store them? Commented Jul 19, 2018 at 11:04
  • And what exactly are you storing in that taxonomy? Is it a full date? Or just a year? Commented Jul 19, 2018 at 11:10
  • Possible duplicate of Using wp_query is it possible to orderby taxonomy? Commented Jul 19, 2018 at 11:39
  • @KrzysiekDróżdż its jsut a year, an integer Commented Jul 19, 2018 at 12:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.