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

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
QJay
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Dec 16, 2018 4:15 am

Sun Dec 16, 2018 4:17 am

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 ‘<# } #>’;
} );

chorn
php-forum Fan User
php-forum Fan User
Posts: 570
Joined: Fri Apr 01, 2016 2:18 am

Sun Dec 16, 2018 11:55 pm

but it is not searchable
what should that mean for anyone not familar with your task? what`s the technical specification of "searchable" in this context?

QJay
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Dec 16, 2018 4:15 am

Mon Dec 17, 2018 7:11 am

Hi
If a listing is located in a mall, I can insert "Mall" into the custom text field. The problem is that you will not be able to find this listing by searching for "Mall".
https://www.myself.dk

Post Reply