Support » Plugin: WP Job Manager » Showing custom multi-select values on job listing

  • Resolved thomastefl

    (@thomastefl)


    I’ve created my own custom fields for my installation of WPJobManager and am running into difficulties displaying the values chosen for multi-select fields.

    By following the instructions here I’ve managed to get custom fields working, and the multi-select fields seem to save when they go to the back-end of WordPress.

    I’m currently calling variables in the job listing using <?php the_variable(); ?> where my custom field is called variable. This isn’t working for multi-select fields. Is there any way of doing this?

    https://wordpress.org/plugins/wp-job-manager/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Mike Jolley

    (@mikejolley)

    <?php the_variable(); ?> is not a valid function. If you add a new custom field, you need to use http://codex.wordpress.org/Function_Reference/get_post_meta to get it’s value.

    The function works for almost any other variable other than multi-select fields. If I have another variable stored in a text field called address, for example, and call <?php the_address(); ?> it will work or if I have options in a drop-down menu titled dropdown and call <?php the_dropdown(); ?> that works too.

    The error that appears when I call that function in the job’s content page for multi-select fields is this: Warning: strlen() expects parameter 1 to be string, array given in /wp-content/plugins/wp-job-manager/wp-job-manager-template.php on line 880

    Plugin Author Mike Jolley

    (@mikejolley)

    Those functions don’t exist – wp-job-manager-template.php only has 560 lines too. I suspect this has been added by another developer…

    You can see the unmodified file here https://github.com/mikejolley/WP-Job-Manager/blob/master/wp-job-manager-template.php#L559

    Yes, I’ve added these lines myself following the instructions that you gave for adding custom fields here. In the default WP Job Manager there is a <?php the_job_type(); ?> function, and plenty others used in content-single_job_listing and my implementation does exactly the same – just replacing job_type with variable.

    I tried to use the post meta but that wouldn’t seem to work either. I’ve tried to look online for anyone else using WPJobManager calling via get_post_meta and haven’t found a guide at all, but I have found one explaining how to call functions the way that I have been.

    Thanks again.

    Plugin Author Mike Jolley

    (@mikejolley)

    I didn’t say add custom functions to the plugin 🙂 You should probably add those via a custom plugin or theme functions.php so you don’t lose them during updates.

    I’d suggest seeing what data is stored for your multiselect using var_dump. e.g.

    var_dump( get_post_meta( $post->ID, '_your_meta_field', true ) );

    See what it gives you. It may be an array, in which case you can handle it differently via your function.

    Hi there, sorry for not getting back sooner.

    This worked fine thanks. Displayed the values on seperate lines by using:

    $metavalues = get_post_meta( $post->ID, '_your_meta_field', true );
    
    echo implode('<br>', $metavalues );

    Hi,

    If type is select, how to show value on single post?

    $fields['_your_meta_field'] = array(
            'label'       => __( 'Salary', 'job_manager' ),
            'type'        => 'select',
    	'options'     => array( 'op1' 	=> 'Choose 1',
    				'op2' 	=> 'Choose 2',),
    );

    It show op1 but I want show Choose 1.

    Please help me!

    Plugin Author Mike Jolley

    (@mikejolley)

    Can you not make your options 'Choose 1' => 'Choose 1'

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Showing custom multi-select values on job listing’ is closed to new replies.