• PPWP is overriding meta query used by any other plugins/theme. Can this be improved ?

    if ( ! is_admin() && $query->is_main_query() ) {
    if ( $post && post_password_required( $post->ID ) ) {
    $meta_query = array(
    array(
    'key' => PPW_Constants::GLOBAL_PASSWORDS,
    'compare' => 'NOT EXISTS',
    ),
    );
    $query->set( 'meta_query', $meta_query );
    }
    }


    if ( defined( 'REST_REQUEST' ) && REST_REQUEST && isset( $query->query_vars['s'] ) ) {
    $meta_query = array(
    array(
    'key' => PPW_Constants::GLOBAL_PASSWORDS,
    'compare' => 'NOT EXISTS',
    ),
    );

    $query->set( 'meta_query', $meta_query );
    }

    An improved version could be:

    if ( ! is_admin() && $query->is_main_query() ) {
    if ( $post && post_password_required( $post->ID ) ) {
    $meta_query = $query->get( 'meta_query', array() ); // Get existing meta queries
    $meta_query[] = array(
    'key' => PPW_Constants::GLOBAL_PASSWORDS,
    'compare' => 'NOT EXISTS',
    );
    $query->set( 'meta_query', $meta_query ); // Merge and set meta queries
    }
    }

    if ( defined( 'REST_REQUEST' ) && REST_REQUEST && isset( $query->query_vars['s'] ) ) {
    $meta_query = $query->get( 'meta_query', array() ); // Get existing meta queries
    $meta_query[] = array(
    'key' => PPW_Constants::GLOBAL_PASSWORDS,
    'compare' => 'NOT EXISTS',
    );
    $query->set( 'meta_query', $meta_query ); // Merge and set meta queries
    }

    This approach ensures that your meta queries are appended rather than overwriting any previously defined meta queries.

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WP Folio Team

    (@buildwps)

    Hello @sajib1223,

    Thank you for sharing this and your proposed solution. The meta_query adjustment is part of how PPWP handles content protection, but we’ll review your suggestion with our development team to assess possible improvements.

    We’ll update you once we have more details. Let us know if you’re facing specific issues related to this!

    Thread Starter Shazzad Hossain Khan

    (@sajib1223)

    Hi,

    We have other plugins that also modify the meta queries for the main query and REST requests. These plugins utilize the pre_get_posts filter with priority levels ranging from 1 to 10. However, the meta queries applied by those plugins are being overridden by PPWP.

    To address this issue, I have temporarily adjusted the priority of those plugins’ filters to 20 to ensure their hooks execute after PPWP’s.

    I hope the development team can review this and consider adopting best practices to prevent such conflicts in the future.

    Thanks.

    Plugin Author WP Folio Team

    (@buildwps)

    Hello @sajib1223,

    Thank you for sharing additional details and your workaround. We’ve forwarded this to our development team, and they’ll review the issue on our end. Any necessary changes to address this conflict will be included in the next release.

    We appreciate your feedback and patience. Let us know if there’s anything else we can assist you with in the meantime!

    Plugin Author WP Folio Team

    (@buildwps)

    Hello @sajib1223,

    We are pleased to inform you that the necessary changes have been included in the latest version of our plugin.

    You can contact us through the form on our website to request access to the updated version.

    We appreciate your feedback and patience throughout this process. Let us know if there’s anything else we can assist you with!

    Thread Starter Shazzad Hossain Khan

    (@sajib1223)

    Thanks, that’s wonderful.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Meta Query Improvements’ is closed to new replies.