• James

    (@jamessui-1)


    Hi,

    I’d like to restrict the fields that are searched (WP ‘post_title’ and an ACF called ‘author’), but only on a certain custom post type – all other post types should use the default ACF: Better Search settings. Is this possible?

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @jamessui-1,

    Thank you for your message.

    Unfortunately, there is no such possibility. The plugin does not affect Custom Post Types searches. The plugin detects the “s” parameter contained in the SQL query and handles it by extending the query to the database.

    Best,
    Mateusz

    Thread Starter James

    (@jamessui-1)

    Thanks – is it possible to turn it off for certain “s” queries?

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @jamessui-1 You can use the following filter:

    add_filter( 'acfbs_is_available', function ( $is_active ) {
    	return $is_active;
    } );

    By modifying return true/false you can turn the search on and off. The filter is used during the init hook. More information can be found in the plugin code in this file.

    Thread Starter James

    (@jamessui-1)

    Thanks for the reply, I’ve tried adding the this code to functions.php to turn off ACF Better Search on a specific CPT archive, but it’s still searching all custom fields, any suggestions?

    	add_filter( 'acfbs_is_available', function ( $is_active ) {
    		if ( is_post_type_archive('past_winners') ) {
    			return false;
    		} else {
    			return $is_active;
    		}
    	} );
    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @jamessui-1 Please set the returned value permanently to false and then check if searching among ACF fields has stopped working. If so, the filter is working and the problem is in your condition.

    Thread Starter James

    (@jamessui-1)

    Thanks for the reply – yeah, if I change the returned value to permanently false it disables searching in ACF fields, on that post type archive page and across the whole site. Any idea why is_post_type_archive doesn’t work within this function? I’ve tried the same condition within a pre_get_posts function to change posts_per_page to test the condition, and that seems to work. Any suggestions?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Restricting fields on certain custom post types’ is closed to new replies.