Skip Navigation

[Resolved] How to show dynamically filtered custom posts?

This support ticket is created 4 years, 12 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 23 replies, has 2 voices.

Last updated by johnD-41 4 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1685609

Tell us what you are trying to do? - I'm trying to list posts which fall under certain categories/taxonomies (which are passed via POST or GET or cookies or a form sumbit).

Is there any documentation that you are following? - I couldn't find any!

Is there a similar example that we can see? - I can show via screenshare what I'm trying to do.

What is the link to your site? - The link wouldn't work outside VPN.

#1686021

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Using Toolset View, you can set your view to filter by specific taxonomy using URL param.

You can check the all available options to filter a view by taxonomy with the following Doc:
=> https://toolset.com/documentation/user-guides/views/filtering-views-by-taxonomy/

To filter a view by specific taxonomy using cookies, you will need to write a custom shortcode that returns the term slug using which you want to filter your view and you can use the taxonomy filter option "Value set by View shortcode attribute" and pass the shortcode as view's shortcode attribute:
=> https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes

Please review that and check if that helps.

#1686025

I assume in order to do this, I must have Toolset Views plugin activated?

If I try to do so, it says that while Toolset Blocks is activated, we can't activate Toolset Views!

Any idea?

#1686039

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

At a time either you can use Toolset Views or Toolset Blocks. Both plugins are 1:1 copy of each other just name is different.

Please check the following blog post:
=> https://toolset.com/2019/11/toolset-views-becoming-toolset-blocks/

#1686105

We are already using Toolset Blocks because we want Toolset Form to be visible on our page. So we definitely can't deactivate Toolset Blocks.

If the Views and Blocks are copy of each other, do we have this Query Filter feature with Blocks also as you have explained - https://toolset.com/documentation/user-guides/views/filtering-views-by-taxonomy/ ?

#1686315

Also, when we submit a Toolset Form, can we add the selected filter values to the query string while navigating to a page/post?

#1686319

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - when you select your block view, on the right panel you will see the "Query Filter" section. '

Please check the following screenshot: hidden link

#1686385

Nope, this is not something I wanted to ask.

I have a Toolset Form for the user to submit which has taxonomies. Now, as an action of that submit button, I want user to go to a page where I want to show the list of items filtered by the taxonomies the user selected in the Toolset Form he/she submitted.

One way, I think this should happen is to include the selected taxonomies in the URL while we submit the form.

Any idea how can I do it? This is basically the reason I wanted Toolset in the first place.

Thank you for your support so far, Minesh. Looking forward.

#1686387

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

After submitting the form if you want the user to redirect to specific page you can use the hook: cred_success_redirect
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

For example:

add_filter('cred_success_redirect', 'func_redirect_to_custom_page',10,3);
function func_redirect_to_custom_page($url, $post_id, $form_data) {
   
   $assigned_terms = wp_get_object_terms( $post_id,'taxonomy-slug',array('fields'=>'slugs'));

    if ($form_data['id']==9999) {
        $url = "";     // adjust your URL with params here
    } 
   
    return $url;
}

Where:
- Replace 9999 with your original form ID and 'taxonomy-slug'

Where within this hook, as you can see we get the assigned terms using the wp_get_object_terms() which will return the term slugs array and you can use this term slug array and pass it as URL param.

#1686429

Ok, I'm trying this right now. However, I'm facing challenges while submitting the form.

Why is it mandatory to add/edit a post after submitting a form? I just want to redirect to a page with the selected parameters in query string and nothing else.

It is not redirecting to that page (via above hook) and rather loading the same page with ?cred_referrer_form_id=122 added to the URL (but stay on the same page).

Why this Form type is mandatory to select? It is a simple form which just submits values to a page (and doesn't create/edit any post/page).

#1686457

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well, Toolset offers three kind of forms:
- post forms (using which you can either create/edit entry for specific post type to which form is attached)
- user forms (using which you can either create/edit users)
- post-relationship forms (using which you can connect the post in pot-relationship)

So, if you created the post form, then either you need to set to create a entry or edit the existing entry.

And as you can see with the following hook, if you want to run the following hook:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
- You need to make sure that:

Please note that for the redirection hooks to work, the form must be set to redirect to a specific page or a post after the submission. If for example, the form options are set to “Keep displaying this form” or “Display a message instead of the form” after submission, the redirection hooks will not work.

#1686459

I see.

However, I don't want post/user/relationship forms. I just need a simple form which has fields filled with custom post's taxonomies and submitting that form will open a new page with the list of items filtered through the items selected in the form (which was submitted).

Any idea how can do this with Toolset Form/View/Blocks?

#1686485

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

There is no such form available. If you want to use the redirection hook I shared, you must create a post form using Toolset.

I am still not clear why you want to create such form as you did not shared the clear requirement.

Maybe you can create a dummy edit form but I would like to know what taxonomy you want to pass as URL param and to what post type the taxonomy is assigned currently.

#1686533

Minesh, can we have a call? A webex/zoom meet? I will be able to explain it better then.

#1686665

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - it seems that you want a custom search view.

Where you want to add a filter for your taxonomy and display the results.

Please check the following Doc where it shows step by step information how you can build the custom search for your post type and add the filters: https://toolset.com/course-lesson/creating-a-custom-search/