This support ticket is created vor 5 Jahren, 10 Monaten. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
I'm trying to do the following and I need some help with the query. I have a View that displays WooCommerce products in a category which is set by the archive that is currently showing.
What I want to do is the following.
1. Query all the prices for products that are in that category. The query must retrieve prices from the field "_sale_price"
2. These values must then populate one dropdown without being duplicated and show in the ascending order.
3. These same values must then populate another dropdown without being duplicated and show in the descending order.
4. The view must then retrieve products between the user selected values from these two dropdown fields. ( >= AND <= )
It is possible with Views plugin, the custom field "_sale_price" is a hidden field, so you can try these:
1) Dashboard-> Toolset-> Settings-> Front-end Content
in section "Hidden custom fields", click button "Select custom fields", and enable option "_sale_price"
- in section "Search and Pagination", click button "New filter", click "Load non-Types custom fields", add the select dropdowns on field "_sale_price", see screenshot: sale_price.JPG
I've tried that and I'm getting values from posts that are not in that category. Which tells me I'll have to modify the Views query which is what I need help with.
Please give me some code on what to modify it so it only searches posts in the current category/archive.
For the question:
Please give me some code on what to modify it so it only searches posts in the current category/archive.
Please check the document I mentioned above: https://toolset.com/documentation/user-guides/filtering-views-by-taxonomy/
See the bottom of above document, there is an option
Value set by current archive page:
Use this setting when you’re adding this Views inside a term archive page and you want it to inherent the taxonomy filtering from the archive term.
The filtering of the posts themselves works OK. I do get the filtered posts. The problem is when I have a filter to filter the posts on that page by a custom field the filter itself is not filtering values according to what's on the page.
The filter picks up all values from that custom field whether the post containing that value is being displayed or not.
You can try it yourself. Just create a view and set it up to show on an archive page by embedding the views code on that page archive.
If you use the default parameter of "source: database" it gets all the values from the database, even if the post that has that value is not being displayed on that page.
There needs to be another option/parameter to use all values retrieved, or to limit the values to what is being shown on the page.
It should be something like "database" or "database-filtered". Then we can choose whether we want all values or just values limited to the posts being displayed at that time.
Luo is on vacation. This is Minesh here and I'll take care of this ticket and try to help you further. Hope this is OK.
Well - As I understand, you want to only display the options in filter for which the posts are currently displayed - correct? If yes:
Would you mind to share problem URL and access details and to which PHP template file you added the view.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
I don't believe there is any problem with my site and it's a standard view that shows posts by the archive. I've created a view to show posts by the archive shown and I've just embedded the php code shown above into the archive page.
Please setup something simple and similar on your own machine and you will see that it gets all the values for that custom field from the database, whether the post is shown on that page or not.
There is nothing in my view that is any different from a standard view. Please try it on your machine and if you are somehow able to achieve what I can't achieve then please post screenshots of your view and I'll duplicate it on my end.
Ok - to eliminate any doubts how you setup your view, can you share full page screenshot of your view and I'm happy to setup the view on my install and test with the archive.
Please confirm below steps:
- I need to setup view as per your screenshot
- I need to add the same view to the post type archive page using PHP tempalte file - correct?
When you edit your view please navigate to the section "Custom Search Settings", if you do not see it, try to find the "Screen Options" button at top right of your page and then checkmark the "Custom Search Settings ".
Once you see "Custom Search Settings" on the page - try to select the option:
- Let me choose individual settings manually
-- further, select the option "Show only available options for each input"
I did have that enabled but I just noticed something interesting. I was playing around with the option to hide or disable the irrelevant results. I noticed that it only works on one of the selectors.
See this image. It does appear to work on the one selector but not on the other. So its probably some kind of scripting error because I'm using the same value for each selector and it does work on one selector but not on the other.
You can see how the unwanted value of 450.00 shows on the "from" selector but it is correctly hidden on the "to" selector.
Thanks for the details, I can duplicate the same problem in my localhost, and escalated it to our 2nd tier supporters, will update here if there is anything news.