Support

Account

Home Forums ACF PRO Problem with search title in PostObject Reply To: Problem with search title in PostObject

  • EDIT:
    Code I posted is bad, this is my code:

    function custom_acf_post_object_query( $args, $field, $post_id ) {
        // Get the search text
        $the_search = $args['s'];
    
        // Remove it so ACF won't search the posts based on title
        unset($args['s']);
    
        // Search based on custom fields only
        $meta_query_args = array(
            'relation' => 'AND', 
            array(
                'relation' => 'OR', 
                array(
                    'key'     => 'post_title', 
                    'value'   => $the_search,
                    'compare' => 'LIKE'
                ),
                array(
                    'key'     => 'content_shop_api_key',
                    'value'   => $the_search,
                    'compare' => 'LIKE'
                )
                
            ),
           array(
                    'key'     => 'free_content_check',
                    'compare' => 'LIKE',
                    'value'   => $the_search,
                )
        );
    
        $args['meta_query'] = $meta_query_args;
    
        return $args;
    }
    
    add_filter('acf/fields/post_object/query/name=assign_user_product', 'custom_acf_post_object_query', 10, 3);