Support

Account

Home Forums Front-end Issues How to sort taxonomy archive by ACF date field?

Helping

How to sort taxonomy archive by ACF date field?

  • The following code works with my custom post type “game”:
    function ptc_customize_wp_query( $query ) {
    if ( $query->is_post_type_archive( 'game' ) ) {
    // Sort portfolio posts by project start date.
    $query->set( 'order', 'DESC' );
    $query->set( 'orderby', 'meta_value_num' );
    // ACF date field value is stored like 20220328 (YYYYMMDD).
    $query->set( 'meta_key', 'release-date' );
    }
    }

    But my custom posts “Game” also have custom taxonomies like “genre”. How can I apply this sorting to these custom taxonomies as well?

  • You cannot order terms by a custom field. You have to build your own sorting mechanism. My first suggestion is going to be doing a web search for “wordpress order terms by custom field”

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.