Skip Navigation

[Resolved] Search by parent post field

This support ticket is created 7 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

Last updated by kaneB 7 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#476412

Hi!

I have:
Parent Post Type: Location
- fields: City
Child Post Type: Listing
- fields: Price

I'm trying to create parametric search with results showing Listings, but based on City and Price. I'm able to show the City in search results showing Listings with:

[types field='city' id='$location'][/types]

Price works as search filter, but the City does not:

[wpv-control field="price" url_param="price_min"]
[wpv-control field="city" url_param="city"]

Is there a way to make wpv-control understand that it's parent's field to search?

I'm not sure if this answer addresses the same issue or if there is a better way?
https://toolset.com/forums/topic/using-multiple-parent-fields-in-parametric-searc/

#476813

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Yes - View will work on the filters of post type to which Views is attached to. But I think I can do something here to achieve your goal but I need to check first on your install if its possible or not.

1)
Could you please share problem URL?

2)
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#477231

Minesh
Supporter

Languages: English (English )

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

I've added following code to your current theme's functions.php file:

add_filter( 'wpv_filter_query', 'custom_search_criteria',10,2);
function custom_search_criteria( $query_args ,$view_settings ) {
  
        if ($view_settings['view_id'] == 5946 and isset($_GET['location-city']) and $_GET['location-city']!="" ) {
 
             $args = array( 'post_type'=>'location',
			                'fields'=>'ids',
                          'meta_query' => array(
                          array(
                            'key' => 'wpcf-location-city',
                            'value' => $_GET['location-city'],
                            'type'=> 'LIKE'
                        )
                )
             );
			 
		$parent_ids = get_posts( $args );
        $parent_ids[] = 0;
		
		if(!isset($query_args['meta_query'])){
            $query_args['meta_query'] = array();
        }
        $query_args['meta_query'][] = array(
            'key'     => '_wpcf_belongs_location_id',
            'value'   => $parent_ids,
            'compare' => 'IN',
        );
            
        }
 
        return $query_args;
}

Now, when you entry city as New York - it will display the post which belongs to New York city.

#477534

Thanks! This definitely solved my problem and explained on how to do similar queries in other searches which need to search based on parent's fields.

#479340

Hi, I have a same setup and I am trying to perform text search on the parent's post title (the default WP post title). The example above is filtering a custom fields, however I want to achieve searching by text box, the post title of the parent, but this option is not available in the filter selection GUI.

Is this achievable? Thanks in advance.

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