I'm using the Flexible Posts Widget to display a list of "deals" (a custom post type) in my sidebar. I'm also using that plugin's capacity to use a custom template to control the display of that listing (see details of how this works on the plugin's installation screen).

One of the meta boxes available in this CPT is a radio button that identifies if the deal is Active or Inactive. On all the "deals" pages (both individual and listings), I've been able to filter the deals so only the "Active" ones show up (like so. However, I can't figure out how to link up with the query run by this plugin and add the ability to exclude deals marked Inactive. I tried using pre_get_posts to this effect, but no luck.

Is it even possible to accomplish this? Or do I need to give up on the plugin and roll my own sidebar query?

In the interim I've added a new WP_Query to the custom template, but understand this is highly inefficient as it pretty much means the query is being run twice. I just haven't been able to get it to work any other way; no luck so far limiting pre_get_posts to just this one query (i.e., not all queries or the main query) or somehow adding in the metakey args after the fact.

// Exclude Inactive Offers from queries
  $args = array(
     'post_type' => 'offers',
     'meta_query' => array(
           'key' => 'offer-status',
           'value' => 'Active'
     'posts_per_page' => '3'
  $offers_query = new WP_Query( $args );
<?php while ( $offers_query->have_posts() ) : $offers_query->the_post(); ?>
  • what other queries for your post type happen on the front end of your site that aren't the main query? you may be able to apply a pre_get_posts action by inference, if that makes sense? for example- if it's a non-admin query for your custom post type, and it's not the main query, it has to be your widget's query if you're not querying that post type anywhere else.
    – Milo
    Commented Aug 21, 2013 at 23:51
  • So, there are two types of "deals" pages: one that lists all current active deals and one that is the page for an individual deal (single-offers.php, if you follow). This latter page also has the flexible posts widget on it. In this instance, the "offers" CPT is being queried via the main loop and again via the widget's query ($flexible_posts).
    – Angelique
    Commented Aug 23, 2013 at 14:42


Your Answer

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