Skip Navigation

[Resolved] Add ACF custom field in the Toolset view Search and Pagination section

This support ticket is created 4 years 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 – 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/Karachi (GMT+05:00)

This topic contains 6 replies, has 2 voices.

Last updated by Waqar 4 years ago.

Assisted by: Waqar.

Author
Posts
#1563541
csf.JPG
sl.JPG

I created a Toolset view to display all my CPT list called "Store Locator", the post has a custom field called "Product"(it's not the woocommerce product), which is created by the ACF plugin(See attachment).

I tried to add a search filter, which is for search store locator with a particular product name. But I can't find it in the custom search filter. The custom field slug is called "re-product".

#1563613

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Wilfred,

Thank you for contacting us and I'd be happy to assist.

To suggest the best way to make the search filter work with a custom field created through a third-party plugin (ACF), I'll need to see exactly how it is set up to store the data.

Can you please share temporary admin login details, along with the link to a page with this post view?

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

#1563909

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Wilfred,

Thank you for sharing the admin access.

I noticed that the custom field that you're referring to is a "Relationship" type field from the ACF plugin.

Since the ACF plugin stores the value in such fields in a serialized data format, there is no built-in or simple way through which that data can be used with Toolset features, including the search filters in views.

Is there any specific reason, you're using a "relationship" field from ACF plugin for this and not Toolset's own "Post Relationship" feature?
( ref: https://toolset.com/documentation/post-relationships/ )

If you'll use Toolset's post-relationship feature for storing these connections, you'll be able to use it for search filters as well:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/how-to-filter-posts-by-their-ancestors/

Note: There are a number of plugins on your website for which newer versions are available and it is always recommended to use the up-to-date plugins.

regards,
Waqar

#1565171

Hi,

I used to be using the toolset relationship for connecting the Store locator and the retailer product CPT, can manage to add the filter in the view.

But we build a mobile app which is connected to the WordPress site database, so I need to create a Rest API for connecting it, when I checking Store locator API JSON, it doesn't have data for assigned retailer product, but ACF have the data, so that why i decide to use ACF for the relationship custom field.

#1565625

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Wilfred,

Thank you for sharing the background information.

In that case, my recommendation would be to keep on using Toolset's post-relationship, as it will allow you to use search filters.

For getting the related posts through REST API, you can register a custom endpoint/route that uses the "toolset_get_related_posts" function.
( ref: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts )

You'll find a good usage example in this reply:
https://toolset.com/forums/topic/writing-rfg-to-cpt-via-rest/#post-1310253

For more personalized assistance around custom code, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#1566587

Hi,

Based on this forum that you give me https://toolset.com/forums/topic/writing-rfg-to-cpt-via-rest/#post-1310253

Can I explain how should I use it?

Thank

function rest_related_posts( $request ){
 
        $parameters = $request->get_query_params();
 
        if ( isset( $parameters['relationship'] ) ) {
 
            $relationship = toolset_get_relationship( $parameters['relationship'] );
 
            if ( $relationship ) {
 
                $parent = $relationship['roles']['parent']['types'][0];
                $child = $relationship['roles']['child']['types'][0];
 
                $post = get_post( $request['id'] );
                $type = $post->post_type;
 
                $origin = ( $parent == $type ) ? 'parent' : 'child';
 
                // Get connected posts
                $connections = toolset_get_related_posts( $post->ID, $parameters['relationship'], array(
                    'query_by_role' => $origin,
                    'role_to_return' => 'other',
                    'return' => 'post_id'
                    )
                );
 
                return implode(',',$connections);
            }
        }
    }

register_rest_route( 'customendpoint/v1', '/related/(?P<id>\d+)', array(
        'methods' => 'GET',
        'callback' => 'rest_related_posts'
    ) );

#1567947

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

As per our support policy, we can guide you around how Toolset Features and functions work.
( ref: https://toolset.com/toolset-support-policy/ )

But for general WordPress, REST API and PHP code customizations, it is recommended to either hire a contractor or consult the specialized community forums:
https://wordpress.org/support/forums/
https://wordpress.stackexchange.com/

Let me briefly explain, what the components in that example code snippet do:

1. "register_rest_route" function:
This WordPress core function registers a new custom REST API route, which can be used in the third-party app.
https://developer.wordpress.org/reference/functions/register_rest_route/

2. "toolset_get_related_posts" function:
This Toolset function can be used to get the list of related/connected posts by specifying the target post, post-relationship, and role in that relationship.
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

I hope this makes it more clear.

regards,
Waqar

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