Skip Navigation

[Resolved] Matching custom field “Post” date field to a CPT custom date field.

This thread is resolved. Here is a description of the problem and solution.

Problem:

I have specific categories of posts that I wish to put on a new CPT page called "From the Print" from a newspaper site. They want it where certain posts show up so many days after publication of the paper version of the newspaper.

Solution:

It does not need [wpv-conditional] shortcode, you can try to add a filter in to the post view, for example:

https://toolset.com/forums/topic/matching-custom-field-post-date-field-to-a-cpt-custom-date-field/#post-1290255

Relevant Documentation:

https://toolset.com/documentation/user-guides/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes

This support ticket is created 4 years, 9 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 10 replies, has 2 voices.

Last updated by bryanC-2 4 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#1289131
custom-field-diagram update.png

Tell us what you are trying to do?

I'm trying to add a custom field date as a marker to a CPT so the CPT will only pull posts with the identical date to the CPT. (Note I am using two different date custom fields with different meta names.)

Is there any documentation that you are following?
Mostly hit and miss Google searches.

I have specific categories of posts that I wish to put on a new CPT page called "From the Print" from a newspaper site. They want it where certain posts show up so many days after publication of the paper version of the newspaper. I believe I know how to do that with views and conditional logic.

My problem is, that I am trying to give the "From the Print" CPT a marker for the posts. To do this I added a date field for the editors to use to designate which post goes on which individual CPT. The post has a "Issue Publication Date" date field and the From the Print CPT has a "Paper Publication Date" date field.

I want it where the writers add the publication date and then when the CPT is created, they add their issue date to match which posts they want on the CPT. If the two date fields match, then the post goes on the individual CPT.

The only thing I could come up with is the code below and that didn't work.

[wpv-conditional if="( [types field='paper-publication-date' output='raw'][/types] eq '[types field='issue-publication-date' output='raw'][/types]')"]
[wpv-post-featured-image]
[wpv-post-link]
[/wpv-conditional]

I had the above in a view (without the needed html styling) and was going to add it with additional views to a content template to break down the categories of the posts for the CPT.

Added is an image to hopefully visually explain what I am hoping for.

Thanks
Bryan

#1289279

Dear Bryan,

Please elaborate the questions with more details.

How do you setup the post types?
I assume we are talking about two post types:
- From the Print
- Posts
Is there any post type relationship between above post types?
https://toolset.com/documentation/post-relationships/

Where do you want put the [wpv-conditional] shortcodes into?
In a single "From the Print" post or single "Post"?

How do you setup those custom date fields?

I need to test it in my localhost, thanks

#1289913

Hi Luo,

I'm sorry I wasn't clear enough. I hope this makes things easier. I created a screencast video that you can download that explains what I am trying to do..

hidden link

There are only two post types. The one I created called "From the Print" and then the core WordPress post type "Posts"

I am creating views that will list certain posts from a certain date that the user chooses in the date field. If this date matches the date field in the "From the Print" CPT then that content/data from that post is allowed to go on the individual "From the Print" post. From there I will filter out through the view, what portions of the post I want to be seen on the From The Print" Post

I have a development site I can give you access to, if you want to see it there. Below also has files you can import to see what I have done so far on a localhost machine. That might be easier.

hidden link

hidden link

Thanks again
Bryan

#1290229

Thanks for the details, I am downloading those files, will update here if there is any found.

#1290255
issuepublicationdate.JPG

In your case, it does not need [wpv-conditional] shortcode, you can try to add a filter in to the post view, it should be more efficient.

For example:
1) Edit the post view "From The Print Obits":
- in section "Query Filter", add a custom field filter:
Select items with field:
Issue Publication Date is a number equal to VIEW_PARAM(issuepublicationdate)
See screenshot issuepublicationdate.JPG,
- in section "Loop item in From The Print Obits", remove the [wpv-conditional] shortcode as below:

[wpv-post-featured-image]
[wpv-post-link]

2) Edit the content template "From The Print Template", you can display "paper-publication-date" field timestamp value of current "From The Print" post with shortcode:
[types field="paper-publication-date" output="raw"][/types]

Pass it as shortcode attribute parameter to above post view's shortcode, like this:

[wpv-view name="from-the-print-obits" issuepublicationdate='[types field="paper-publication-date" output="raw"][/types]']

Then test again, check if it is what you want.

I have tested it in my localhost, it works fine.

More help:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes
section "Controlling the filter with shortcode attributes"

#1291263

Thanks for all the good information. I tried it once, but was unsuccessful. I didn't have time to dig deeper over the weekend. I'm going to try again in the morning and also create a basic test localhost site to see if I can get it to work. Please keep this ticket open while I do this and I will get back to you on my results in a day or two. I'm optimistic.

Thanks
Bryan

#1291329

OK, please update here if you still need assistance, thanks

#1292235

Hi again Luo

I'm afraid I can't get this working for me. I tried this on the live site where it was suppose to go and then I created a small localhost machine with the basics on it and I can't get either to work. I get a "no content found" message. This with marking all or just one of the categories.

If I take the custom field filter out, the posts will start to appear, but not because the dates match.

I believe I have it set up exactly like you told me too.

Below is a Dropbox Links to the custom fields
hidden link

Below is to the Views and Templates
hidden link

And below is to the content I used on my localhost. (If needed)
hidden link

Does everything look right in there?

Thanks
Bryan

#1292245

Please provide a test site with the same problem, I can setup a demo for you, thanks

#1294287

Thanks for the details, I can log into your website, I have done below modifications in your website:
Edit the post view "From The Print Obits":
hidden link
in section "Query Filter", replace the filter from:
Select items with field:
Paper Publication Date is a number equal to VIEW_PARAM(issuepublicationdate)

To:
Select items with field:
Issue Publication Date is a number equal to VIEW_PARAM(issuepublicationdate)

Test it in front-end:
hidden link

I can see it works fine, please check if it is fixed, thanks

#1295227

Your software is great. I love using it and I learn something new everytime.

Thanks

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.