Skip Navigation

[Resolved] Display posts using field from another post type.

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

Problem: I would like to show a list of links to posts that is filtered by two custom fields representing the current User ID and the current post ID.

Solution: - Create a View of Library Articles with no filters
- In the Loop Output of the View, insert a post link shortcode.
- Use the wpv-post-field shortcode to set the post link "item" attribute. This will allow you to display the post link of another post, using the custom field value.

[wpv-post-link item="[wpv-post-field name='wpcf-current-post-id']"]

Replace current-post-id with the slug of your current post ID field from wp-admin. Be sure to keep the wpcf- prefix here, it's required.

You also mentioned that there is a current User ID field on the Library Article post. If you want to filter this list by the current User's ID (like a "My Library" list), go back to the View and add a custom field filter based on the user ID field. Choose the option "set by one shortcode attribute", and make that attribute something like "userid". Now in your View's shortcode, you can pass the current User's ID into the filter using the shortcode attribute. So the View shortcode would look something like this:

[wpv-view name="your-library-article-view" userid="[wpv-user field='ID']"]

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/
https://toolset.com/documentation/user-guides/views-shortcodes/
https://toolset.com/documentation/customizing-sites-using-php/functions/

This support ticket is created 5 years, 6 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by rachelP-2 5 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1279037

Tell us what you are trying to do?
I am implementing an "Add to my library" feature on my blog.
I have a custom post type called "Library Articles" with 2 custom fields: current post ID and current reader ID.
There is a CRED form on each post which, when clicked, creates a Library Article with just the current post ID and the current reader ID.
Now I need a view which will show all posts with ids that are saved as Library Article current post IDs.
Can you help me with this?

Is there any documentation that you are following?

Is there a similar example that we can see?
https://toolset.com/forums/topic/create-an-add-to-favourites-function-just-like-toolsets-website/

What is the link to your site?
hidden link

#1279067

Hi, if I understand you correctly this should be fairly straightforward. Here's how I would set it up:
- Create a View of Library Articles with no filters
- In the Loop Output of the View, insert a post link shortcode.
- Use the wpv-post-field shortcode to set the post link "item" attribute. This will allow you to display the post link of another post, using the custom field value.

[wpv-post-link item="[wpv-post-field name='wpcf-current-post-id']"]

Replace current-post-id with the slug of your current post ID field from wp-admin. Be sure to keep the wpcf- prefix here, it's required.

You also mentioned that there is a current User ID field on the Library Article post. If you want to filter this list by the current User's ID (like a "My Library" list), go back to the View and add a custom field filter based on the user ID field. Choose the option "set by one shortcode attribute", and make that attribute something like "userid". Now in your View's shortcode, you can pass the current User's ID into the filter using the shortcode attribute. So the View shortcode would look something like this:

[wpv-view name="your-library-article-view" userid="[wpv-user field='ID']"]

This technique is called passing arguments to Views, and is explained in more detail here: https://toolset.com/documentation/user-guides/passing-arguments-to-views/

#1280273

That worked perfectly! Thanks for the quick support.