Forums › Forums › Search & Filter Pro › Cannot filter on custom wp post
- This topic has 14 replies, 2 voices, and was last updated 6 years ago by Anonymous.
-
Anonymous(Private) January 8, 2019 at 1:16 pm #198330
Hello,
I recently bought this plugin but I am having problems starting it work.I have custom posts called ‘trainer’ with custom fields (ACF).
I want to display filtering on custom template (archive-trainer.php), where right now I have:<?php echo do_shortcode('[searchandfilter id="1513"]'); echo get_trainers(); ?>
The function get_trainers contains custom WP query
function get_trainers() { $html = ''; $args = array( 'showposts' => 10, 'post_type' => 'trainer', ); // attach S&F do_action("search_filter_query_posts", 1513); $query = new WP_Query( $args ); $trainers = $query->posts; var_dump( $GLOBALS['wp_query']->request); var_dump($trainers); }
In S&F admin I have set display results method: custom and I have provided correct url of the page where the archive is.
If I var_dump last query, no S&F filtering is performed ๐
Could you please give me a hint what I am missing? ๐Thanks
KarelAnonymous(Private) January 8, 2019 at 2:16 pm #198347I do get full set of results, when this line is or is not present.
The only difference is when the line is present is this statement in SQL wp_posts.ID IN (1284,1495,1503,1504,1505,1506,1508) (and this statement is there if i try filtering anything…Trevor(Private) January 8, 2019 at 2:27 pm #198353Ah, I see. I misunderstood your initial question. I am sorry for that. At least, I think I understand.
Showing the word searched for is not so difficult. If you have other filters, then it becomes a little more complex, but I can give you links. The documentation page:
https://searchandfilter.com/documentation/accessing-search-data/
This thread might help you:
https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/
โฆ and this search will give similar threads I think:
https://support.searchandfilter.com/forums/search/sf_current_query+get_array+field+%5Bvalue%5D/
Anonymous(Private) January 8, 2019 at 2:37 pm #198357Well I might have asked wrong way ๐
The thing is the filter as I call it with the shortcode shows up, but if I try to filter results (e.g. I select one region in the dropdown or white a text to the search input and press submit), nothing changes – the result set of $trainers remains unchanged (unfiltered), so as the $GLOBALS[‘wp_query’]->request).
From your first link you provided, I tried this code:
$sf_current_query = $searchandfilter->get(1513)->current_query(); echo '<pre>'; print_r($sf_current_query->get_array()); echo '</pre>';
and got
array (size=10) 'paged' => int 1 'search_filter_id' => int 1513 'search_filter_override' => boolean false 'posts_per_page' => int 10 'post_status' => array (size=1) 0 => string 'publish' (length=7) 'meta_query' => array (size=0) empty 'post_type' => string 'trainer' (length=7) 'is_search' => boolean true 'is_archive' => boolean true 'post__in' => array (size=7) 0 => int 1284 1 => int 1495 2 => int 1503 3 => int 1504 4 => int 1505 5 => int 1506 6 => int 1508
(notice there is no sign of filtering in the array). This is my main problem.
Anonymous(Private) January 8, 2019 at 2:40 pm #198359It seems the filtering request (for example I write ‘Jane’ to the search input, or select region 1) does not come to the query. I believe I went through the documentation but I am not sure if I am missing something how to link the S&F filter with the WP Query so the filtering would work…
Anonymous(Private) January 8, 2019 at 3:15 pm #198390I created a new page called Test, inserted
[searchandfilter id="1513"] [searchandfilter id="1513" show="results"]
then in S&F admin changed Display results method using shortcode and changed result url
And the filter does not work the very same way as on custom template with custom WP query ๐
I even tried to deactivate all plugins ๐ -
AuthorPosts