Forums › Forums › Search & Filter Pro › Custom Post Query On Archive Page
Tagged: custom query
- This topic has 3 replies, 2 voices, and was last updated 9 years, 3 months ago by Ross.
-
Anonymous(Private) August 12, 2015 at 8:48 pm #23144
Hi,
I have used your plugin and I have used the widget on a custom post type archive page, but i noticed you have stated we cant use it when we use a custom query (archive.php page).
I need retrieve a custom query before displaying the posts as i need it to be dynamic based on the user role of the user signed in.
Im guessing i cant use your plugin for my particular situation. Or can i somehow pre get posts?
Regards
Nick
Ross Moderator(Private) August 13, 2015 at 11:41 am #23184Hey Nick
You can use pre get posts but with specific priority – check here for an example:
https://support.searchandfilter.com/forums/topic/single-author-page-customisation-advice/#post-21108
Just so you are aware – S&F 2.0 gets rid of this (as in, using pre_get_posts will no longer be recommended) but there is a similar filter to replace this
Thanks
Anonymous(Private) August 13, 2015 at 11:17 pm #23211Hi Ross,
When is the S&F 2.0 being released? i read the post and it said it will be a built in feature where it will recognise custom queries in a page and include them in the search? is this right?
Im using a custom query like below, do i wait for the update? or will the code below work with the code you sent me in the link?
<?php // args $args = array( 'numberposts' => -1, 'post_type' => 'event', 'meta_key' => 'location', 'meta_value' => 'Melbourne' ); // query $the_query = new WP_Query( $args ); ?> <?php if( $the_query->have_posts() ): ?> <ul> <?php while( $the_query->have_posts() ) : $the_query->the_post(); ?> <li> <a href="<?php the_permalink(); ?>"> <img src="<?php the_field('event_thumbnail'); ?>" /> <?php the_title(); ?> </a> </li> <?php endwhile; ?> </ul> <?php endif; ?> <?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
cheers nick
Ross Moderator(Private) August 14, 2015 at 12:26 pm #23223Hi Nick
S&F generally does not work with other custom queries, but there is usually enough settings to create access most of the WP_Query settings straight in the S&F UI.
So you can use the pre_get_posts method I described the above or in actual fact you could probably create that query in the settings of S&F – just head to the “post meta” tab and add a default against the meta key
location
formelbourne
Thanks
-
AuthorPosts