@epsilonadmin custom block.
Here is info how to create block - https://www.advancedcustomfields.com/blog/acf-5-8-introducing-acf-blocks-for-gutenberg/
So we register new block, assigned fields for this block.
We add block on page. When I try to search phrase from one of these field - page not added to search result
Filter and sort result list
-
Do we have ability to sort and filter search result? For example, filter result by pages / pdf / doc / etc? Sort by relevance or date?
Maybe you have values that I can use to rewrite a query? -
Hi @ilocimwca
Yes, of course, all the same values that you're usually using for WP_Query() will work!
You can specify parameters in case you want to call WP_Query() manually or you can use the pre_get_posts hook in case you want to intercept the main query.
What do you actually plan to do?
-
@epsilonadmin I planned pre_get_posts. How to filter to show only pdf or only web pages?
-
Hi @ilocimwca
It's simple to do with this addon
https://fulltextsearch.org/wpfts-addon-files-only-1.0.1.zipIt contains some code to limit post_type to 'attachment' only:
add_action('pre_get_posts', function(&$wpq) { if ($wpq->is_search && $wpq->is_main_query()) { $wpq->set('post_type', array('attachment')); $wpq->set('post_status', array('inherit')); } });
Pretty simple. If you want to set up your own post_types, just modify this code. You can read about full WP_Query() parameters at the Wordpress official documentation.