0

This is linked to a previous question here: https://stackoverflow.com/questions/76095044/re-ordering-a-custom-post-type-query-performed-by-directorist-plugin/76095177#76095177

I am using a listing plugin Directorist that creates a custom post-type that I wanted sorted by plan type. I was able to achieve this by using this code:

function custom_at_biz_dir_query( $query ) {
// Check if the query is for the custom post type at_biz_dir
if ( isset( $query->query_vars['post_type'] ) && $query->query_vars['post_type'] == 'at_biz_dir' ) {
    // Order the posts by the presence of the _fm_plans meta_value
    $query->set( 'meta_key', '_fm_plans' );
    $query->set( 'orderby', 'meta_value_num meta_value' );
    $query->set( 'meta_query', array(
        'relation' => 'OR',
        array(
            'key' => '_fm_plans',
            'compare' => 'EXISTS',
            'type' => 'NUMERIC',
        ),
        array(
            'key' => '_fm_plans',
            'compare' => 'NOT EXISTS',
        ),
    ) );
    $query->set( 'order', 'ASC' );
    //$query->set( 'paged', get_query_var( 'paged' ) ?: 1 );
}
}
add_action( 'pre_get_posts', 'custom_at_biz_dir_query' );

The code works but creates a pretty big issue. When editing any of the taxonomies, including categories, tags, and the custom taxonomy for the listing type, it either make all listings go to the trash, expired, or private.

I have tried to do something as simple as adding "if (! is_admin())" but then pagination doesn't work.

Any thoughts on how to resolve this? Also, I HAVE reached out to the plugin developers with no luck. It's poorly developed and has things like //test $var = "lhlhlkh" in production code. so...

0

Your Answer

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