Title: Custom query
Last modified: December 21, 2016

---

# Custom query

 *  Resolved [candell](https://wordpress.org/support/users/candell/)
 * (@candell)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/custom-query-8/)
 * I initially set up the plugin on my custom post type archive page and using the
   basic loop
 *     ```
       <?php do_action('show_beautiful_filters'); ?>
       <?php if (have_posts()) : ?>
       <?php while (have_posts()) : the_post(); ?>
       etc etc
       ```
   
 * and this worked great.
 * However I want to modify the query to run off a date field I set with Advanced
   Custom Fields
 *     ```
       <?php do_action('show_beautiful_filters'); ?>
       <?php 
       $timecutoff = date("Yjd");
       $args = array(
       'post_type' => 'sc_jobs',
       'orderby' => 'meta_value',
       'meta_key' => 'closing_date',
       'meta_compare' => '>=',
       'meta_value' => $timecutoff,
       'order' => 'ASC'
       );
       $my_query = new WP_Query($args);
   
       if ($my_query->have_posts()) : while ($my_query->have_posts()) :
       $my_query->the_post();
       ?>
       ```
   
 * How do I pass to beautiful taxonomy filters my new query $my_query?
 * Thanks
    -  This topic was modified 9 years, 7 months ago by [candell](https://wordpress.org/support/users/candell/).

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

 *  Plugin Author [Jonathan de Jong](https://wordpress.org/support/users/jonathandejong/)
 * (@jonathandejong)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/custom-query-8/#post-8615301)
 * Hi Candell,
 * Instead of creating your own wp_query you should modify the existing one.
    Use
   the `pre_get_posts` filter in WordPress to add your meta information to the search
   query and it’ll work with the basic loop and BTF! [https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Exclude_Pages_from_Search_Results](https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Exclude_Pages_from_Search_Results)
 *  Thread Starter [candell](https://wordpress.org/support/users/candell/)
 * (@candell)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/custom-query-8/#post-8633712)
 * Thanks for the reply Jonathan, I am struggling to get this to work with pre_get_posts(
   and thanks for educating me to this filter, I can see many uses for it going 
   forwards).
 * Here’s my function
 *     ```
       add_filter( 'pre_get_posts', 'jobs_query_for_beautiful_filters' );
       function jobs_query_for_beautiful_filters( $query ) {
       $timecutoff = date("Ymd");
   
       $jobsquery = array(
       array(
       'post_type' => 'sc_jobs',
       'orderby' => 'meta_value',
       'meta_key' => 'closing_date',
       'meta_compare' => '>=',
       'meta_value' => $timecutoff,
       'order' => 'ASC'
       )
       );
       $query->set( 'jobs_query', $jobsquery );
       }
       ```
   
 * The posts to display are located in my archive-cptjobs.php file displaying the
   loop for the custom post type which is now using
 *     ```
       <?php do_action('show_beautiful_filters'); ?>
       <?php if (have_posts()) : ?>
       <?php while (have_posts()) : the_post(); ?>
       etc etc
       ```
   
 * However posts with a past date are still showing.
 * Thanks
 *  Plugin Author [Jonathan de Jong](https://wordpress.org/support/users/jonathandejong/)
 * (@jonathandejong)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/custom-query-8/#post-8633957)
 * Hi Candell,
 * Look into the meta_query parameter instead.
    [https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters](https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters)
 * Also, don’t modify the entire query, just set the parameters you want to change.
   
   [https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts](https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts)
 * For example:
    `$query->set( 'orderby', 'meta_value' );`
 *  Thread Starter [candell](https://wordpress.org/support/users/candell/)
 * (@candell)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/custom-query-8/#post-8635223)
 * Got it working, thank you Jonathan

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

The topic ‘Custom query’ is closed to new replies.

 * ![](https://ps.w.org/beautiful-taxonomy-filters/assets/icon-256x256.png?rev=1654967)
 * [Beautiful taxonomy filters](https://wordpress.org/plugins/beautiful-taxonomy-filters/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/beautiful-taxonomy-filters/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/beautiful-taxonomy-filters/)
 * [Active Topics](https://wordpress.org/support/plugin/beautiful-taxonomy-filters/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/beautiful-taxonomy-filters/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/beautiful-taxonomy-filters/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [candell](https://wordpress.org/support/users/candell/)
 * Last activity: [9 years, 6 months ago](https://wordpress.org/support/topic/custom-query-8/#post-8635223)
 * Status: resolved