Home › Forums › Support › Moving from WP Show Posts to Generatepress Blocks Pro: How to do with Query Loop
- This topic has 3 replies, 3 voices, and was last updated 5 months, 1 week ago by
Fernando.
-
AuthorPosts
-
October 10, 2022 at 11:01 am #2369088
C.K.
We are currently using WP Show posts with custom shortcodes: [wp_show_posts id=”56565″ settings=”category&tax_term=amazon&meta_key=price&orderby=meta_value_num&order=ASC”]. We are moving to Generatepress Blocks Pro since WP Show posts is going away. How do we make this shortcode work with the same outcome using the Query Loop block builder? (Excluding category, tax-term, order ascending – have figured those out already)
I think we need to register these other custom post type taxonomies from reading up on support threads, etc. but I am not completely sure.
October 10, 2022 at 1:02 pm #2369182Ying
StaffCustomer SupportHi there,
We can use the filter
generateblocks_query_loop_args
to order by meta key.For example,add
my-query-2
to the class list of my Post Template Block within the Query Loop Block as such: https://share.getcloudapp.com/P8uQ5j2WThen, you can add this code for
meta_key
andorder_by
:add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-query-2' ) !== false ) { $query_args['meta_key'] = 'price'; $query_args['orderby'] = 'meta_value_num'; } return $query_args; }, 10, 2 );
You can add order parameter and set it to ASC in the query loop block.
Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets
Hope this helps!
October 10, 2022 at 2:51 pm #2369247C.K.
Thanks Ying!
I will elaborate a little on this, as believe I may have left out some key details.
I’m sorry I didn’t provide these details previously!
I do think your team helped set this up previously in Show Posts Pro.We have somewhat interesting queries we achieved through Custom Post Types UI and WP Facet Search – which a WP Show Posts shortcode with extra parameters (settings) had everything functioning properly between each of the pieces. The post grids were filterable by the facet dropdown choices, and we only show 9 on a page at a time, with a show more button that pulls up the rest of the posts included in that facet/filter.
The extra arguments/settings in the Show Posts shortcode allowed the filtering/sorting with Facet Search.
The lists were then being sorted by price with a function for the ‘facet archive pages’:
function fwp_archive_per_page( $query ) {
if ( is_tax( ‘destination’ ) || is_tax( ‘interest’ ) ) {
if ($query->is_main_query()) {
$query->set( ‘orderby’, ‘meta_value_num’ );
$query->set(‘meta_key’, ‘price’);
$query->set( ‘order’, ‘ASC’ );
}
}return $query;
}
add_filter( ‘pre_get_posts’, ‘fwp_archive_per_page’ );It seems that we just need to ‘register’ the filterable taxonomies in the query loops so they accept the added queries from facet search.
How can we transfer or can we even achieve these extra settings from the shortcode in a query loop block?
Let me know your thoughts if you get a chance to look at the pages real quick with your login.
Thanks for your time and help!October 11, 2022 at 7:10 pm #2370521Fernando Customer Support
Hi C.K.,
How about adding this in the code to test?
$query_args['tax_query'] = array( array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => 'amazon', ), );
-
AuthorPosts
- You must be logged in to reply to this topic.