Skip Navigation

[Resolved] Filter view by shortcode based on custom field values

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

Problem:

The problem here is that the user is filtering their view by a shortcode parameter, however when a shortcode is passed into the view parameter the formatting breaks.

Solution:

In order for you to do a shortcode in shortcode type setup you will need to first ensure that you're creating a content template with our Toolset plugin. The nested shortcode setup will only work with Toolset.

This is because wordpress core dropped support for using shortcodes as attributes.

A few other plugins have added support for this but if you're creating a page through wordpress core then it won't work.

This support ticket is created 3 years, 3 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 15 replies, has 2 voices.

Last updated by tomasP 3 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#2141125
Snímek obrazovky 2021-08-12 v 16.33.19.png
Snímek obrazovky 2021-08-12 v 16.32.41.png
Snímek obrazovky 2021-08-12 v 16.32.24.png
Snímek obrazovky 2021-08-12 v 16.32.04.png

Hello,
1) I have a custom number field which can have multiple values - post IDs of posts of the same type. (see image attached)
2) I have a view that should filter out only posts with the ID values stored in the custom field.
3) I am trying to filter the view with Post ID filter using the "Posts with IDs set by the View shortcode attribute" option (see image attached)
4) in the page I have a shortcode for the view (see image attached)
5) I have found this ticket - https://toolset.com/forums/topic/custom-field-in-filter-with-shortcode-attribute-parameter-not-working/ but I cannot get it to work. The view is not filtered and there is some bug in the syntax - possibly some brackets, quotes,...
6) If I type some real post ID in the view shortcode, the filter works just fine...

Getting desperate, could you help, please?
Thanks very much in advance
Tom

#2141349

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Tom,

Thank you for getting in touch. A simple way to debug this is to check what are the actual values that are being passed into the view.

If you use this shortcode below you should be able to tell what the view is getting.
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-attribute

The shortcode is to be added inside your view and it will display the value being passed into the parameter. From there you should be able to verify that the values are correct as well as the formatting.

Thanks,
Shane

#2141613
Snímek obrazovky 2021-08-13 v 5.32.31.png
Snímek obrazovky 2021-08-13 v 5.32.48.png
Snímek obrazovky 2021-08-13 v 5.41.29.png
Snímek obrazovky 2021-08-13 v 5.41.08.png

Hello, Shane,
thanks very much for your reply. Unfortunately, the shortcode (see image attached) doesn't do anything in my case. I think the syntax error [/types]"] is the cause (see image attached). Note: I have deactivated all other plugins and the error remained.
When I change the view shortcode attribute "souvisejici" to a existing postID (4742), the shortcode works as expected (see images attached)

#2142031

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Tomas,

Perhaps the shortcode block isn't able to process the nested shortcodes.

Can you add this to a Toolset Fields and Text block and let me know if the results are the same? If they are please provide me with admin access to the site so that I can have a further look at this for you.

Thanks,
Shane

#2142033

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

private fields

#2142043

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Tomas,

The site appears to be on a private server.

Can you provide the details for this as well.

Secondly I need a link to the page where you are testing this.
Thanks,
Shane

#2142053

Hello, Shane,
login credentials sent in private message - the shortcode is in the footer section, so i can be seen anywhere on the site.

#2142057

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2021-08-13 at 9.41.34 AM.png

Hi Tomas,

The credentials sent are for the wordpress backend and not to access the site. The credentials that I want are for this login bar. See Screenshot.

Without logging in there first, i'm not able to access the site.

Thanks,
Shane

#2142075

Hi, Shane,
are you using some proxy in your browser? This bar should not appear, it is a live site

#2142083

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Tomas,

No i'm not, also I notice this only occurs when i try to access the wp-admin url. Going to any other page on the site displays the website.

However lets see if we can make some progress without logging in. Clearly what is happening is the shortcode is breaking when passed as a parameter.

Given that you are using a number field then you can just format it like this below.


[wpv-view name='my-view' param="[types field='number'][/types]"]

No need to add additional parameters to the types shortcode as it will always output a raw value.

Thanks,
Shane

#2142097
Snímek obrazovky 2021-08-13 v 17.18.45.png

Hi, Shane,
no, still no go - same result 🙁
this is the shortcode now

#2142117

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Tomas,

In this case I will definitely need to log in to see the issue first hand.

Perhaps you can use this plugin below.
https://wordpress.org/plugins/temporary-login-without-password/

This should allow you to generate a temporary login URL for me. This might be able to allow me to bypass the login popup.

Thanks,
Shane

#2142913

Hi Shane,
I have updated the private message with the temporary link. Thanks again for your efforts!

#2143823

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Tomas,

I'm still unable to get onto the site even with the login temporary URL. I've asked a colleague to check as well and they didn't have any luck either.

The only other option is to ensure that on your server that you're not requiring the server login for access to the page. Alternatively you can provide a copy of the entire site but this can be there as a last resort if no other access method works.

To provide the copy you can follow the information in the link below.
https://toolset.com/faq/provide-supporters-copy-site/

You can exclude all the images from the site since I will just be checking the view. I've enabled the private fields once more again.

Thanks,
Shane

#2144071

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Tomas,

Thank you I was able to get on and found the issue.

It appears that your view with the shortcode parameter wasn't added to the content template below
hidden link

It was added to a different section that isn't processed by views. Now if the shortcodes are processed directly by wordpress core then the nested shortcodes will break because wordpress had removed support for the using as shortcode as attribute.

In order for the nesting of the shortcodes to work correctly you will need to add it to the content template as I did in my example.

If you check the page you sent you will see i've added "SHANE TEST" to the section followed by the view shortcode.

Thanks,
Shane