• Resolved kcmau

    (@kcmau)


    I have the following WP_Query that is suppose to get the 6 most recent broadcasts ordered by the Monday’s start date (monday_start_date is a custom field), but the results are in random order because WHP seems to be overriding the meta_key. WHP is not enabled on the Broadcast custom post type.

    
    $args = array(
             'post_type' => 'broadcast',
             'posts_per_page' => 6 ,
             'order' => 'DESC',
             'orderby'  => 'meta_value_num',
             'meta_key' => 'monday_start_date',
    );
    $the_query = new WP_Query($args);
    pr($the_query); // print_r wrapper
    

    And here is a snippet of the output …

    
    WP_Query Object
    (
        [query] => Array
            (
                [post_type] => broadcast
                [posts_per_page] => 6
                [order] => DESC
                [orderby] => meta_value_num
                [meta_key] => monday_start_date
            )
    
        [query_vars] => Array
            (
                [post_type] => broadcast
                [posts_per_page] => 6
                [order] => DESC
                [orderby] => meta_value_num
                [meta_key] => _whp_hide_on_cpt_archive
                [error] => 
                ...
            )
    ...
    )
    

    Notice in the [query] section on the of the WP_Query Object the meta_key is set to what I asked it for, ie. “monday_start_date” but in the [query_vars] and key in [meta_query] sections it has been overridden with “_whp_hide_on_cpt_archive”. If I disable WHP then the meta_key and key revert to monday_start_date and WP_Query works as expected.

    Current versions:
    Wordpress 5.9.2
    WHP 1.0.2

    I have only just picked up on the issue but I have confirmed that it has only broken in the following update.

    WHP 0.5.4 => 1.0.1

    Please help.

    Kind Regards,
    Pete

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter kcmau

    (@kcmau)

    UPDATE

    It seems WHP may be applied to all post types regardless of the chosen post types setting. After a little investigation I believe I may have found a bug and I think it may be due to a missing set of brackets in whp-hide-posts/inc/class-post-hide.php on line 100 in the “exclude_posts” function.

    if ( ! is_admin() || ( is_admin() && wp_doing_ajax() ) && ...

    I believe this should be …

    if ( (! is_admin() || ( is_admin() && wp_doing_ajax() ) ) && ...

    Without the extra brackets just the !is_admin() is enough for the whole condition to be true whenever you are not an administrator. Adding the extra brackets seems to resolve my issue but I have not thoroughly tested the change.

    Please check and confirm?

    Regards,
    Pete

    • This reply was modified 2 years, 11 months ago by kcmau.

    The last update of this plugin made a random mess of our staging site. We rely heavily on the Content Views plugin. I believe the bug you have found breaks Content Views queries. I just added the outer parentheses as you have suggested (in our staging site) and it fixes our problem.

    Wendy

    Plugin Author MartinCV

    (@martin7ba)

    @kcmau Thank you for that bug catch. I will have this updated.

    @wendybreaksout Sorry about the Random mess.

    Plugin Author MartinCV

    (@martin7ba)

    The bug is fixed and plugin is updated

    Thread Starter kcmau

    (@kcmau)

    Glad to help. Cheers!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WP_Query meta_key being changed by WHP’ is closed to new replies.