Skip Navigation

[Resolved] wprelated to ids

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

Problem:

How to display different contents on custom field value empty or not?

Solution:

You can use [wpv-conditional] shortcode to check if the custom field isn't empty, then display the view shortcode, for example:

Relevant Documentation:

https://toolset.com/forums/topic/wprelated-to-ids/#post-2346011

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 4 replies, has 2 voices.

Last updated by martinP-13 1 year, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#2345325

you must login to see the pages ,use toolset and toolset. (if you neeed wp-admin please set me a private reply)

i have a post type "dog"
i have custom field group for the "post type named Dog info".
i have 2 fields named "sire and dam" they are set as select fields , so if i enter a dog it , that dog can then be set as the sire or dam of any new dogs i enter via the 2 fields select box.

when a dog has a dam and sire set ,the system and display work perfect. like this example
hidden link this is correct , the backend for this dog is here hidden link , if you notice it has the dam and sire set and works perfect.

when a dog has NO dam or sire set it will list ALL dogs as the dam and sire like this example
hidden link the back end for this dog is here hidden link if you notice this dog has the dam and sire as "not set"

so the problem is not displaying the relevant dogs as sire or dam , but rather it is showin all dogs when unset ,when in fact it should display nothing.

how the view is constructed.

so the dog page uses this view
hidden link which then uses
[wpv-view name="view-to-show-dogs-related-sire-and-dam-single-dog-page" ids="[types field='sire-of-dog' output='raw'][/types]"]

the view [wpv-view name="view-to-show-dogs-related-sire-and-dam-single-dog-page" ids="[types field='sire-of-dog' output='raw'][/types]"]

uses the loop with

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>

!<span style="color:red">[types field='dogs-awards' separator=', '][/types] </span>!*[wpv-post-link]* <br>
Breeder: [wpv-post-link item="@person-dog.parent"]<br>

[wpv-conditional if="( '[types field='person-affix-before' item='@person-dog.parent'][/types]' eq '' )"][/wpv-conditional]
[wpv-conditional if="( '[types field='person-affix-before' item='@person-dog.parent'][/types]' ne '' )"]Breeder Affix: [types field='person-affix-before' item='@person-dog.parent'][/types] <br>[/wpv-conditional]

[wpv-conditional if="( '[types field='judges-panel' item='@person-dog.parent'][/types][types field='judges-book-number' item='@person- dog.parent'][/types]' eq '' )"][/wpv-conditional]
[wpv-conditional if="( '[types field='judges-panel' item='@person-dog.parent'][/types][types field='judges-book-number' item='@person- dog.parent'][/types]' ne '' )"]JUDGE STATUS: [types field='judges-panel' item='@person-dog.parent'][/types][types field='judges-book- number' item='@person-dog.parent'][/types][/wpv-conditional]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

the queery is set as

Post ID filter Posts with IDs set by the View shortcode attribute:
ids

thanks for any insight you can shed on this matter .
martin

#2345831

Hello,

I have tried the username/password you provided above, but get below errors:
ERROR: The username or password you entered is incorrect.

Please share your website admin credentials in below private message box, thanks

#2346011

Hello,

That is expected result, when the field value is empty, and you pass empty value to view to filter the result, Views will return all results.

In your case, you can use [wpv-conditional] shortcode to check if the custom field isn't empty, then display the view shortcode, for example:

[wpv-conditional if="( $(wpcf-sire-of-dog) eq '' )" evaluate="false"]
"sire-of-dog" field isn't empty, here display specific view's shortcode 
[/wpv-conditional]
#2346801

thankyou for that , the conditional was causing me errors so i used a different statement which got me sorted ,thanks for the help it was invaluable. i have the same sort of issue going on in another view , im using

<h3>Sire</h3>[wpv-view name="view-3435" ids="[types field='sire-of-dog' output='raw' item='@dog-dog-appearance.parent'][/types]"]<hr>

how would i wrap that in a condition ? none seem to work ?

ie , if the field sire-of-dog is completed show the view 3435 , if not completed do not show the view 3435?

once agin thanks so much for the assistance

martin

#2346955

My issue is resolved now. Thank you!

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