WordPress.org

Forums

WP Job Manager
[resolved] Showing custom multi-select values on job listing (9 posts)

  1. thomastefl
    Member
    Posted 7 months ago #

    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/

  2. Mike Jolley
    Member
    Plugin Author

    Posted 7 months ago #

    <?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.

  3. thomastefl
    Member
    Posted 7 months ago #

    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

  4. Mike Jolley
    Member
    Plugin Author

    Posted 7 months ago #

    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

  5. thomastefl
    Member
    Posted 7 months ago #

    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.

  6. Mike Jolley
    Member
    Plugin Author

    Posted 7 months ago #

    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.

  7. thomastefl
    Member
    Posted 7 months ago #

    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 );
  8. nhobaby
    Member
    Posted 6 months ago #

    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!

  9. Mike Jolley
    Member
    Plugin Author

    Posted 6 months ago #

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

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.