Title: Plugin is breaking meta_query
Last modified: July 24, 2017

---

# Plugin is breaking meta_query

 *  Resolved [Dalton Rooney](https://wordpress.org/support/users/daltonrooney/)
 * (@daltonrooney)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/plugin-is-breaking-meta_query/)
 * We’ve been using SEO Framework on a site for quite a while now without any problems.
   With version 2.9.3, we did notice a problem with one of our site functions. We’ve
   got a home-made “related posts” function that uses WP_Query with a meta_query
   argument (with “OR” relation”) to display a few posts.
 * With 2.9.3, however, the meta query is no longer working and _all_ posts are 
   returned. Here’s the SQL that’s generated by WP_Query with SEO Framework disabled:
 * `SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.
   post_id ) WHERE 1=1 AND ( ( wp_postmeta.meta_key = 'agents_0_agent' AND wp_postmeta.
   meta_value = '21294' ) ) AND wp_posts.post_type = 'property' AND (wp_posts.post_status
   = 'publish' OR wp_posts.post_status = 'acf-disabled' OR wp_posts.post_status 
   = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.menu_order ASC`
 * Here’s the SQL that’s generated by WP_Query with SEO Framework enabled (returns
   all posts)
 * `SELECT wp_posts.* FROM wp_posts LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.
   post_id ) LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.
   meta_key = 'exclude_from_archive' ) WHERE 1=1 AND ( ( wp_postmeta.meta_key = '
   agents_0_agent' AND wp_postmeta.meta_value = '21294' ) OR ( mt1.post_id IS NULL))
   AND wp_posts.post_type = 'property' AND (wp_posts.post_status = 'publish' OR 
   wp_posts.post_status = 'acf-disabled' OR wp_posts.post_status = 'private') GROUP
   BY wp_posts.ID ORDER BY wp_posts.menu_order ASC`
 * I’ve verified that reverting to version 2.9.2 fixes the problem.
 * **Update** I did a little searching and found [https://github.com/sybrew/the-seo-framework/issues/167](https://github.com/sybrew/the-seo-framework/issues/167)
 * Disabling the search filters did the trick:
 *     ```
       add_action( 'init', function() {
       	$tsf = function_exists( 'the_seo_framework' ) ? the_seo_framework() : null;
       	if ( isset( $tsf ) ) {
       		remove_action( 'pre_get_posts', array( $tsf, 'adjust_search_filter' ), 9999 );
       		remove_action( 'pre_get_posts', array( $tsf, 'adjust_archive_query' ), 9999 );
       	}
       } );
       ```
   
 * Any thoughts on if this is a permanent change or if it will be reverted at some
   point?

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

 *  Plugin Author [Sybre Waaijer](https://wordpress.org/support/users/cybr/)
 * (@cybr)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/plugin-is-breaking-meta_query/#post-9349375)
 * Hi [@daltonrooney](https://wordpress.org/support/users/daltonrooney/),
 * I’m glad you’ve found a resolution on your own, awesome!
 * The meta query will be exchanged with something else, issue 167 currently has
   the highest priority and will be released with 2.9.4.
    Because the proposed solution
   in that issue can’t work with pagination (WordPress uses SQL for that), a new
   option will also be added that simulates the snippet you’ve posted.
 * With that, everything will be (directly or indirectly) fixed.
 *  [mintynz](https://wordpress.org/support/users/mintynz/)
 * (@mintynz)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/plugin-is-breaking-meta_query/#post-9394378)
 * I was using the excellent WooCommerce Extra Product Options plugin and I think
   this is the reason they have SEO Framework listed as an incompatible plugin:
   
   [https://codecanyon.net/item/woocommerce-extra-product-options/7908619](https://codecanyon.net/item/woocommerce-extra-product-options/7908619)
 * A support post from me got the following response from the developer (see below).
 * Does it seem like the upcoming update will fix the same issue?
 * Cheers,
    Minty
 * —————
    I have determined the cause of this issue.
 * It’s in the file \autodescription\inc\classes\init.class.php and this is the 
   code:
 * \add_action( 'pre_get_posts', array( $this, 'adjust_archive_query' ), 9999, 1);
   
   public function adjust_archive_query( $query ) {
 *  // Don't exclude pages in wp-admin.
    if ( ( $query->is_archive || $query->is_home)&&!
   $this->is_admin() ) {
 *  $meta_query = $query->get( 'meta_query' );
 *  //* Convert to array. Unset it if it's empty.
    if ( ! is_array( $meta_query ))
   $meta_query = $meta_query ? (array) $meta_query : array();
 *  /**
    * Exclude posts with exclude_from_archive option on. * * Query is faster
   when the global relation is not set. Defaults to AND. * Query is faster when 
   no value is set. Defaults to 'IS NULL' because * of 'compare'. Having no effect
   whatsoever as it's an exclusion. */ $meta_query[] = array( array( 'key' => 'exclude_from_archive','
   type' => 'NUMERIC', 'compare' => 'NOT EXISTS', ), );
 *  $query->set( 'meta_query', $meta_query );
    } }
 * When this executes it overrides the plugin’s own meta query and there isn’t anything
   in the code to make to do that from my end, thus the incompatibility.
 *  [thinkwired](https://wordpress.org/support/users/thinkwired/)
 * (@thinkwired)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/plugin-is-breaking-meta_query/#post-9396798)
 * Can I revert to 2.9.2 without worrying about the DB? Is it simply a code change?
 *  Thread Starter [Dalton Rooney](https://wordpress.org/support/users/daltonrooney/)
 * (@daltonrooney)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/plugin-is-breaking-meta_query/#post-9396804)
 * [@thinkwired](https://wordpress.org/support/users/thinkwired/) Better to use 
   the filter I referenced above to remove the query modification than to try to
   support an out of date version of the plugin.
 *  [thinkwired](https://wordpress.org/support/users/thinkwired/)
 * (@thinkwired)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/plugin-is-breaking-meta_query/#post-9481076)
 * Has this been fixed in the latest version?
 *  Plugin Author [Sybre Waaijer](https://wordpress.org/support/users/cybr/)
 * (@cybr)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/plugin-is-breaking-meta_query/#post-9481205)
 * Hi [@thinkwired](https://wordpress.org/support/users/thinkwired/),
 * Yes, this has been alleviated in the latest version; but, manual action is required
   as only big sites and certain plugins are affected by this issue:
    1. Go to SEO Settings.
    2. Go to General Settings -> Performance.
    3. Adjust Archive Query alteration settings to your liking.
 * How the options affect your site is described above the settings. If you’re still
   unsure, let me know!
 * A permanent solution is being considered, which should make the options redundant
   in regards to performance and conflict:
    [https://github.com/sybrew/the-seo-framework/issues/182](https://github.com/sybrew/the-seo-framework/issues/182)
    -  This reply was modified 8 years, 9 months ago by [Sybre Waaijer](https://wordpress.org/support/users/cybr/).
      Reason: clarity
 *  [thinkwired](https://wordpress.org/support/users/thinkwired/)
 * (@thinkwired)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/plugin-is-breaking-meta_query/#post-9481216)
 * So, if I uncheck both of those boxes, the only thing I lose is the ability filter
   on-site search results?
 * BTW, having those boxes checked causes my db to become unresponsive. The query
   just runs too long.
 *  Plugin Author [Sybre Waaijer](https://wordpress.org/support/users/cybr/)
 * (@cybr)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/plugin-is-breaking-meta_query/#post-9481232)
 * Hi [@thinkwired](https://wordpress.org/support/users/thinkwired/),
 * That’s correct, the related settings will be made unavailable.
 * If you’d still wish to maintain the ability for “the odd one out” exclusion, 
   then you could also opt-in for “On the site”. That will work through PHP instead
   of SQL, in an exclusive manner after the query is done (ergo why 404 pages could
   form if overdone).
 *  [thinkwired](https://wordpress.org/support/users/thinkwired/)
 * (@thinkwired)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/plugin-is-breaking-meta_query/#post-9481234)
 * That is fine, we do not use the on-site search filter.
 * Thank you for your time/reply.

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

The topic ‘Plugin is breaking meta_query’ is closed to new replies.

 * ![](https://ps.w.org/autodescription/assets/icon.svg?rev=3000376)
 * [The SEO Framework – Fast, Automated, Effortless.](https://wordpress.org/plugins/autodescription/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autodescription/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autodescription/)
 * [Active Topics](https://wordpress.org/support/plugin/autodescription/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autodescription/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autodescription/reviews/)

 * 9 replies
 * 4 participants
 * Last reply from: [thinkwired](https://wordpress.org/support/users/thinkwired/)
 * Last activity: [8 years, 9 months ago](https://wordpress.org/support/topic/plugin-is-breaking-meta_query/#post-9481234)
 * Status: resolved