• Resolved monkeytreecreative

    (@monkeytreecreative)


    Hi again,

    I’ve run into a small issue and hopefully you can point me in the right direction again.

    The PRICE filter – from an ACF Field – does not work because the POSTS are ordered by the PRICE.

    Below is the function on how the archive is being ordered:

    function wpb_custom_query( $query ) {
        if( $query->is_main_query() && ! is_admin() && $query->is_archive() ) {
        	$query->set( 'meta_key', 'price' );
            $query->set( 'orderby', 'meta_value_num' );
            $query->set( 'order', 'ASC' );
        }
    }
    add_action( 'pre_get_posts', 'wpb_custom_query' );

    Like I said, all the other filters work fine, but for some reason the PRICE filter is not working and I presume its because of how I am ordering the posts.

    Many thanks in advance! Any help will be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author stepasyuk

    (@stepasyuk)

    Hi @monkeytreecreative

    Indeed it looks like there is conflict between WP_Query modified by Filter Everything and this sorting code that also modified WP_Query. I think you can make them compatible if you use inner Filter Everything hook

    do_action( 'wpc_filtered_query_end', $wp_query );

    that fires after filters modified WP_Query. If you will attach your sorting code to this hook you can make it compatible with filtered WP_Query.

    • This reply was modified 2 years, 10 months ago by stepasyuk.
    Thread Starter monkeytreecreative

    (@monkeytreecreative)

    Hi @stepasyuk,

    Thanks again for the swift response. Have used the code below, which works fine. Once again, thanks for your support. Brilliant.

    do_action( 'wpc_filtered_query_end', $query );
    function wpb_custom_query( $query ) {
        if( $query->is_main_query() && ! is_admin() && $query->is_archive() ) {
        	$query->set( 'meta_key', 'price' );
            $query->set( 'orderby', 'meta_value_num' );
            $query->set( 'order', 'ASC' );
        }
    }
    add_action( 'wpc_filtered_query_end', 'wpb_custom_query' );

    Cheers!

    Plugin Author stepasyuk

    (@stepasyuk)

    Super. I’m glad ??

    Thank you for your review.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Specific Filter Not Working With Custom Orderby’ is closed to new replies.