Skip Navigation

[Closed] Views

This support ticket is created 4 years, 1 month 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)

Tagged: 

This topic contains 13 replies, has 2 voices.

Last updated by Christian Cox 4 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1863361

Tell us what you are trying to do?
I have to 2 custom post types"Seller" and "paidviewer". I created a view for the seller post type to show all items. Is it possible within toolset to have a condition whiles looping through each post to compare certain fields values in the paidviewer post type?

For example.
In the paidviewer post type I have 2 custom fields that stores the Seller post ID and the the current users ID when a new post is created. In the Seller view I would like a condition within each post to take the post id and current user id and compare those values to the paidviewers custom fields. If match yes else no.

Is there any documentation that you are following?
No Documentation
Is there a similar example that we can see?
No
What is the link to your site?
hidden link

#1863711

Hello, I can try to help but it depends on what you want to do with this condition, and how you have built the Seller View.
- Can you explain in more detail what you want to accomplish in the Seller View results when a matching Paid Viewer post exists, and what you want to accomplish when no matching Paid Viewer post exists?
- What if more than one matching Paid Viewer post exists for a single Seller result?
- Are you using the Block Editor to design the Seller View, or the legacy Views editor?

#1863933
explaination.jpg

I have attach a image explaining what I want to achieve . What I want to see the text in red. I can give you access to the site if required.

#1863953

Yes it would be helpful to see the wp-admin area. Please provide admin access in the private reply fields here.

#1864687

Okay I see your Seller View on the homepage. In each result of the Seller View, I think you want to find any PaidViewer posts that have matching custom field values for the current Seller ID and current User ID. If any matching PaidViewer post is found, you want to display some specific content. If no matching PaidViewer post is found, you want to display some alternate content. A conditional will not help much here, since there is more than one possible PaidViewer post and you need to test all of them for matching values. The only way to test multiple PaidViewer posts like this is with a View of the PaidViewer post type, or with custom code. You would need to create a separate View of the PaidViewer post type, filtered by custom field values, and insert that View inside the loop of the Seller View. This isn't currently possible in Blocks, because you cannot create nested Views using the Block Editor. The only way to achieve this is with the legacy Views editor. It is a shortcode-based solution that requires some understanding of HTML and shortcodes. If you'd like more information about this, I can help, but if you're looking for a pure Block Editor solution I'm afraid there is not a good one right now in the current software. Until nested Views are supported in the Block Editor designer, the legacy approach is the only option available that does not involve custom PHP code.

#1864691

Yes I would like more help creating please.

#1864761
shortcode-seller-id.png

Okay first you must enable the legacy Views editor in Toolset > Settings > General tab: "Editing Experience". You can enable both the Blocks experience and the legacy Views experience here.

Then a Views menu item will appear in the main Toolset menu in wp-admin. Click that link and create a new View. In the popup, choose the option "Display all results" and name the View. Then in the View Editor page, choose the PaidViewer post type in Content Selection. Scroll down and find the Limit and Offset section, and set a limit of 1.

Then scroll down to the Query Filter section and click "Add a filter". Choose the Seller ID custom field from the PaidViewer fields, then choose the options to compare the field value as a "number" equal to a shortcode attribute "seller_id". See shortcode-seller-id.png for an example.

Click "Add a filter" again and repeat this process to select the user ID field. Compare the field value as a number equal to a shortcode attribute "user_id".

Now scroll down to the Loop Editor and click "Skip wizard". Inside the wpv-loop tags, enter some text like this:

<wpv-loop>
Matching PaidViewer found
</wpv-loop>

This text will be displayed if a matching PaidViewer is found.

Then replace the text "No items found" with some other text like this:

<strong>[wpml-string context="wpv-views"]No matching PaidViewer found[/wpml-string]</strong>

We will use this text to test the View, then change it later. Save the View and return to the Seller View in the Block Editor.

Insert a Custom HTML block in the View's Loop block and paste the following shortcodes to place the new PaidViewer View with the required shortcode attributes defined:

[wpv-view name="your-view-slug" seller_id="[wpv-post-id]" user_id="[wpv-current-user info='id']"]

Replace your-view-slug with the slug of your PaidViewer View. You can find the View slug near the top of the View Editor page when you edit the PaidViewer View.

Save the Seller View page in the Block Editor and check on the front-end of the site. The View should show "Matching PaidViewer found" or "No matching PaidViewer found" for each Seller post.

Let me know if you are able to get this working as expected, or if you get stuck. We can continue from there.

#1864869

I get this error Only lowercase letters and numbers allowed as shortcode attributes when I try to save the view

#1864873

the view is called paidviewer view

#1864891

Okay let's change the shortcode attribute names to "sellerid" and "userid" instead of "seller_id" and "user_id". Then you can use the updated shortcode below in your Seller View:

[wpv-view name="your-view-slug" sellerid="[wpv-post-id]" userid="[wpv-current-user info='id']"]

Replace your-view-slug with the actual slug of the PaidViewer View. You can find the slug in the View editor page.

#1864929

sorry please ignore my last response

#1864933

I think it's working thank you very much

#1864939

Now I need to work out how to put the link to view the post. what would you recommend?

#1864991

Okay great. Inside the PaidViewers View, if you want to show a link to the current Seller post, you can access the sellerid shortcode attribute passed into the PaidViewers View shortcode to create a custom HTML link using the wpv-post-url shortcode. For example:

<a href="[wpv-post-url item='[wpv-attribute name="sellerid"]']">View Seller</a>

More information about passing arguments to Views and the shortcodes involved can be found in these documents:
https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-url
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-attribute

The topic ‘[Closed] Views’ is closed to new replies.