Home › Forums › Pro Support › How to get the template part working with WPSP?
Tagged: template
- This topic has 47 replies, 3 voices, and was last updated 4 years, 11 months ago by
Tom.
-
AuthorPosts
-
June 8, 2018 at 2:08 am #4825
Alberto
ParticipantHi Tom!
Let’s see if I can explain the current situation to you:
I’m working with WPSP and also with Search & Filter plugin.
I can show my posts in the way I wish when I’m in the archive page (see picture) but if I use the search and filter plugin the results are showed in the content display of the theme (see picture). So I add a taxonomy.php file to my child-theme but I want to render the results as the posts are showed by the WPSP plugin so I wonder if there is a way to achieve this more easily than creating a content with the html structure that I’d use with get_template_part() inside the loop.Thanks in advance.
June 8, 2018 at 9:08 pm #4839Tom
KeymasterHey Alberto,
What does the filter plugin do exactly? Does it allow you to filter things using certain parameters (taxonomy, terms etc..)?
June 12, 2018 at 2:11 am #4884Alberto
ParticipantHi Tom!
Sorry for not replying sooner, I was waiting to receive an email notifying me of your reply but the emails don’t arrive.Yes, the plugin works like a wordpress search, allowing you to filter by taxonomy and terms. So I think if WPSP works with the search results page it could be works also with this plugin… Is it possible?
Thanks in advance!
June 12, 2018 at 7:53 pm #4897Tom
KeymasterHmm, you would need to grab the variables set by the search plugin, and plug them into the settings parameter in the shortcode/plugin.
For example:
$custom_settings = array( 'taxonomy' => 'value_from_search', 'tax_term' => 'value_from_search', ); wpsp_display( 123, $custom_settings );
It would require you to use PHP in order to grab those variables from the search plugin.
June 13, 2018 at 5:43 am #4908Alberto
ParticipantThanks for replying!
I’m not sure where I should use that code… The parameters are setting in a custom page (“locutores”) where I use the WPSP shortcode, and the plugin redirects me (when I do my search and filter) to an archive (taxonomy) page.
Can you tell me where I should use that code?Thanks!
June 13, 2018 at 8:29 pm #4910Tom
KeymasterThat code would need to go into a custom template (taxonomy.php in your case I think).
Something like this wouldn’t work with shortcodes, as we need to gather values from the search plugin.
June 15, 2018 at 1:08 am #4927Alberto
ParticipantHi Tom!
Thank you for pointing me in the right direction.
I was trying with your code in taxonomy.php and it works when I filter one taxonomy, but I work with two taxonomies (Gender and Age), so if I want to filter, for example, the posts belong to ‘Female’ and ‘Adult’ I try with this code$custom_settings = array( 'relation' => 'AND', array( 'taxonomy' => 'gender', 'tax_term' => $gender ), array( 'taxonomy' => 'age', 'tax_term' => $age ), ); wpsp_display( 123, $custom_settings );
But it doesn’t works.
Colud you tell me how to solve this?Thanks in advance!
June 15, 2018 at 8:59 pm #4941Tom
KeymasterSo it works when you do this?:
$custom_settings = array( array( 'taxonomy' => 'gender', 'tax_term' => $gender ), );
June 18, 2018 at 1:21 am #4953Alberto
ParticipantYes, it works if I try to filter by gender (or If I try by age), but I need it filtering by gender and age.
June 18, 2018 at 8:19 pm #4967Tom
KeymasterMaybe try this:
$custom_settings = array( 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'gender', 'tax_term' => $gender ), array( 'taxonomy' => 'age', 'tax_term' => $age ), ) ); wpsp_display( 123, $custom_settings );
June 19, 2018 at 1:32 am #4975Alberto
ParticipantHi Tom!
Thanks for your suggest but it seems not to works.
This is the result of $custom_settings var_dump:array(1) { ["tax_query"]=> array(3) { ["relation"]=> string(3) "AND" [0]=> array(2) { ["taxonomy"]=> string(6) "gender" ["tax_term"]=> string(6) "female" } [1]=> array(2) { ["taxonomy"]=> string(3) "age" ["tax_term"]=> string(5) "child" } } }
The result’s page show all the posts, without filtering.
I’ve also tried with:
$custom_settings = array( 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'gender', 'terms' => $gender ), array( 'taxonomy' => 'age', 'terms' => $age ), ) ); wpsp_display( 123, $custom_settings );
And with:
$custom_settings = array( 'post_type' => 'locuciones', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'gender', 'terms' => array($gender), ), array( 'taxonomy' => 'age', 'terms' => array($age), ), ) );
What could be wrong with that?
Thanks in advance.
June 19, 2018 at 8:39 pm #4980Tom
KeymasterThat’s strange, looks like the right syntax: https://stackoverflow.com/a/45969347/2391422
I’ll dig into the plugin a bit to see if it’s a bug.
June 20, 2018 at 1:29 am #4985Alberto
ParticipantHello Tom!
According to the syntax reference you’ve given me, I’ve tried with this code:$custom_settings = array( 'post_type' => 'locuciones', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'gender', 'field' => 'slug', 'terms' => $gender ), array( 'taxonomy' => 'age', 'field' => 'slug', 'terms' => $age ), ) );
But I’m still getting all the posts as result…
I’ll appreciate so much if you’d take a look at the WPSP plugin code.
Thanks in advance.
June 26, 2018 at 1:46 am #5033Alberto
ParticipantHi Tom!
Any news on how to solve this problem?
Days go by and I need to find a solution for my client.Thanks
June 27, 2018 at 8:08 pm #5053Tom
KeymasterNo news yet..
If you set this up using a new WP_Query (no WPSP), do the arguments work?
-
AuthorPosts
- You must be logged in to reply to this topic.