Support » Plugin: WP Job Manager » Snippet do not work: “Make custom meta field searchable”

  • Resolved qjay

    (@qjay)


    Hi
    Hope someone can help me to make a new custom field searchable. The field works perfectly, but it is not searchable.

    Here is the code snippet for Make custom meta field searchable:

    function my_wpjm_meta_key_dm() {
    global $wpdb, $job_manager_keyword;
    $searchable_meta_keys[] = ‘_event_felt’;
    return $searchable_meta_keys;
    }
    add_filter(‘job_listing_searchable_meta_keys’, ‘my_wpjm_meta_key_dm’);

    Here is another solution I have tried, but following code do not not work either:

    function my_wpjm_meta_key_dm( $searchable_meta_keys ) {
    global $wpdb, $job_manager_keyword;
    $searchable_meta_keys[] = ‘_event_felt’;
    return $searchable_meta_keys;
    }
    add_filter(‘job_listing_searchable_meta_keys’, ‘my_wpjm_meta_key_dm’);

    Here is the custom code for the new field I have made, which works perfect, but is not searchable:

    add_filter( ‘submit_job_form_fields’, ‘frontend_add_event_field’ );;

    function frontend_add_event_field( $fields ) {
    $fields[‘job’][‘event_felt’] = array(
    ‘label’ => __( ‘If the Store is located in a Shopping Mall’, ‘job_manager’ ),
    ‘type’ => ‘text’,
    ‘placeholder’ => ‘Insert Name of Mall – level & store number’,
    ‘priority’ => 1
    );
    return $fields;
    }

    add_filter( ‘job_manager_job_listing_data_fields’, ‘admin_add_event_field’ );

    function admin_add_event_field( $fields ) {
    $fields[‘_event_felt’] = array(
    ‘label’ => __( ‘If the Store is located in a Shopping Mall’, ‘job_manager’ ),
    ‘type’ => ‘text’,
    ‘placeholder’ => ‘Insert Name of Mall – level & store number’,
    ‘description’ => ‘description’
    );
    return $fields;
    }

    add_action( ‘single_job_listing_meta_end’, ‘display_event_felt_data’ );

    function display_event_felt_data() {
    global $post;

    $event = get_post_meta( $post->ID, ‘_event_felt’, true );

    if ( $event ) {
    echo ” . __( ‘<br>’ ) . ‘ ‘ . esc_html( $event ) . ‘<br><br>’;
    }
    }

    function custom_listify_widget_job_listing_map_before() {
    global $post;

    $event = get_post_meta( $post->ID, ‘_event_felt’, true );

    if ( $event ) {
    echo ” . __( ‘<br>’ ) . ‘ ‘ . esc_html( $event ) . ”;

    }}

    add_filter( ‘listify_widget_job_listing_map_before’, ‘custom_listify_widget_job_listing_map_before’ );

    add_filter( ‘listify_get_listing_to_array’, function( $data, $listing ) {

    $date = $listing->get_object()->_event_felt;

    // Only add if our custom field is not empty.
    if ( ” !== $date ) {
    $data[‘date’] = $date;
    }

    // Return modified list of data.
    return $data;
    }, 10, 2 );
    /**
    * Output our custom field in the Javascript template.
    *
    * This placeholder is replaced by the value of the data set above.
    */
    add_action( ‘listify_content_job_listing_meta’, function() {
    // Check if available.
    echo ‘<# if ( data.date ) { #>’;

    // Output inside a <div>
    echo ‘<div class=”my-date-field”>{{data.date}}</div>’;

    // End check.
    echo ‘<# } #>’;
    } );

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Jen H.

    (@jenhooks)

    Hi @qjay,

    This is the snippet we’ve made available in our public documentation:

    function my_wpjm_meta_key_dm() {
        global $wpdb, $job_manager_keyword;
        $searchable_meta_keys[] = '_my_meta_field';
        return $searchable_meta_keys;
    }
    add_filter('job_listing_searchable_meta_keys', 'my_wpjm_meta_key_dm');

    I’d recommend using a plugin like Code Snippets to add this code to your site, rather than adding it directly to functions.php:

    https://wordpress.org/plugins/code-snippets/

    Beyond this guidance, assistance with implementing customizations is outside of the scope of the support that we offer, per our Support Policy:

    https://wpjobmanager.com/support-policy/.

    If you need it, you can search for development help in a variety of places — here are a few to start:

    http://jobs.wordpress.net/
    https://jetpack.pro/
    https://codeable.io/?ref=l1TwZ

    I’ll leave this open for a few days in case there’s someone else in the community who would like to chime in and lend a hand.

    Best of luck.

    Plugin Contributor Richard Archambault

    (@richardmtl)

    I’m marking this thread as Resolved as it’s been more than a month since the last reply. If you still need help, please do reply again and mark the thread as Unresolved!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Snippet do not work: “Make custom meta field searchable”’ is closed to new replies.