[Resolved] Display only the latest post with duplicated taxonomy
This thread is resolved. Here is a description of the problem and solution.
Problem:
How to Order child posts by taxonomy with custom date field
Solution:
You can use view's filter hook wpv_filter_query to modify the view's query on fly and adjust it as per your requirement by hooking custom query filters to it.
I have a CPT that list the "prices" and the "stores" that sells them. Each "price" has a field for "Date" and "Store" is set as a taxonomy of "price". There can be multiple "prices" added and some of they would have the same "store".
EG:
Price 1 Store 1 Date 31Jan
Price 2 Store 2 Date 1Feb
Price 3 Store 1 Date 1Feb
My objective is to display only one "price" with the latest "date" for a particular "store".
Price 2 Store 2 Date 1Feb
Price 3 Store 1 Date 1Feb
Hello. Thank you for contacting the Toolset support.
Well - as per the information shared by you about your structure, "Store" is setup as taxonomy - correct? If yes:
You should create nested view - one view to loop through your store taxonomy, so you should create a new taxonomy view and another view to loop through your posttype and add this view within the taxonomy view's loop output.
How would this nested views solve me "showing only the post with the latest date"? I understand it clubs the taxonomy together but I need to display only one - the one with the latest date.
I have tried this and my issue now is that while i can club the "stores" together, i cannot sort the price because sorting will follow the taxonomy view's sorting. How do i achieve that?
Price 1.00 Store 1 Date 31Jan
Price 2.00 Store 2 Date 1Feb
Price 3.00 Store 1 Date 1Feb
It now displays:
Price 3.00 Store 1 Date 1Feb
Price 2.00 Store 2 Date 1Feb
I need it to display :
Price 2.00 Store 2 Date 1Feb
Price 3.00 Store 1 Date 1Feb
In addition, the "Price" is a child post of "Product" post type and the suggested taxo nested views currently sits in a child post view of the product content template.
Well - this needs custom query as you can not control the child view order by and that you can not merge with order by of parent view.
Still - it will be great if you can share temporary access details with problem URL and what view's you are using and I will check if I can offer you any solution.
*** 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.
Ok - thanks for sharing all required access and I checked your current setup.
You said:
The display in view 3.1 is the correct prices but i want it to display only the latest price per "store".
==> This means that the you want to display latest price per store with latest date with date field belongs to "Price Date" - correct?
So, for example:
=> hidden link
-- When displaying above project - it should display the price which is having date value 07/02/2018 as "Price Date" - correct?
Perfect. I need FTP access details as I need to add some filters.
*** 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.
Thanks Dinesh, this is definitely one big leap towards the desired outcome.
I have tested, and seem to have some small issue: I have added some new prices both into new "store" and existing "store", and it seems it wont take the latest "price".
hidden link
Price 1659 (2.18) not showing (should override price 1656-2.19)
Price 1662 (2.86) not showing (should override price 1630-2.87)
Price 1665 (3.87) not showing (should override price 1626-3.88)
I also only want this checking logic to apply to "normal" price only. "Normal" is in the price type post field.
I have looked at the code again, i think you made comparison to "price" instead of "price date". My test confirms that the filter above compares the unique "price" instead of the date. See price 1670 (2.19) manage to replace price 1656 (2.19).
Thanks Dinesh, seems to be comparing the date field now with your amendment.
Two queries:
1. It doesn't seem to work backwards, as in if i changed an old date to a later date, it will still show the "latest added date". Is it because the variable was not reset?
2. How do i compare this only on "normal" price type? It's one of the post field.
Two queries:
1. It doesn't seem to work backwards, as in if i changed an old date to a later date, it will still show the "latest added date". Is it because the variable was not reset?
==> Could you please tell me example record which you edited and should display with the result? or what exact result it should show after changing the date.
2. How do i compare this only on "normal" price type? It's one of the post field.
==> What is your normal price type field? how you want to compare it? could you please open a new ticket for your each new question. This will help other users searching on the forum.