Filter search of Experts based on custom field

I have created a custom field called "colors" for Experts custom post types in J&E. I'd like to use a function with an add_filter on jbp_expert_search_params to restrict the search results which are generated by /expert-archive/main.php. Specifically, I only want results to appear in search that have "colors"="red".

Can you provide a function to do so?

Thank you

  • Ivan
    • Developer

    Hi Tahiti Sunshine !

    You could try adding the following snippet in a MU plugin ( more info about MU plugins is here )

    <?php
    function wpmu_jobs_plus_today_expert( $args ) {
        $args['meta_key'] = 'colors';
        $args['meta_value'] = 'red';
    
    	return $args;
    }
    add_filter( 'jbp_expert_search_params', 'wpmu_jobs_plus_today_expert' );

    Best,
    Ivan.

  • Tahiti Sunshine
    • Design Lord, Child of Thor

    Hi Ivan,

    Thanks for your response. The functions works well when added to functions.php. However, I need to add the functionality directly within /expert-archive/main.php. I understand that I will have to redo this change to the code after updating J&E in the future - that's ok.

    Can you modify the code so that it can be added above the line "setup_postdata(get_post($pro->id));" in main.php?

    Thanks again

  • Ivan
    • Developer

    Hi Tahiti Sunshine !

    You can try to add the following code above that line

    $colors = get_post_meta( $pro->id, 'colors', true );
    if ( 'red' !== $colors ) {
        continue;
    }

    Note: since this public forum I should warn other people - DON'T EDIT CODE OF ANY PLUGINS EVER, USE A CHILD THEME, MU PLUGINS OR SEPARATE YOUR CUSTOM PLUGINS FOR IT.

    Best,
    Ivan.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.