Custom Post Query On Archive Page

Forums › Forums › Search & Filter Pro › Custom Post Query On Archive Page

Tagged: 

Viewing 4 posts – 1 through 4 (of 4 total)
  • Anonymous
    #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
    #23184

    Hey 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
    #23211

    Hi 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
    #23223

    Hi 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 for melbourne

    Thanks

Viewing 4 posts – 1 through 4 (of 4 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.