CalderaWP / searchwp-api-route

Adds an endpoint to the WordPress REST API for searching via SearchWP
33 stars 15 forks source link

Setting the default post_type to 'post' nullifies search results for searches in CPT's #5

Open rlaan opened 8 years ago

rlaan commented 8 years ago

Hi Josh,

Thanks for your awesome plugin, I use it for a project and it really helps me out a lot.

Just a quick remark from my end, a while ago I upgraded to the latest version. After the upgrade all my search results where gone.

After some digging into the upgrade, I found the default posttype is set to 'post' and since I wasn't searching posts (or pages for that matter) I didn't get any search results.

I have circumvented this by using the 'ys_cwp_swp_api_args' filter, like this:

function ys_cwp_swp_api_args( $args ) {

    if ( isset( $args[ 'post_type' ] ) ) {
        unset( $args[ 'post_type' ] );
    }
    return $args;
}
add_filter( 'cwp_swp_api_args', 'ys_cwp_swp_api_args' ,10, 1 );

I thought I mention this to you, and perhaps help out other people in the process as well.

Thanks, Ruud