• Resolved akschoeck

    (@akschoeck)


    Hi there.

    I am using Wp-Job-Manager in conjunction with the Listify theme. I am attempting to use the wp_set_post_tags PHP function somewhere in the \templates\job-submit.php file to take a custom field submission and edit the tags of that post accordingly. (I will use the false parameter from the wp function to reset the tags completely instead of appending them). I am mostly certain I can build out the PHP function myself, but I’m not sure where to put it.

    I’m no PHP expert, but I am able to find my way around where I typically need. I am just complete inexperienced in dealing with forms, so I’m just not sure how to go about doing this. Can I add an onclick PHP function to the submit button? Or do I need to do something with the form action?

    I’m not sure I’m doing a great job of explaining, and can provide more details in a private message of sorts (skype/email?), as the website is currently private.

    https://www.ads-software.com/plugins/wp-job-manager/

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

    (@mikejolley)

    Thread Starter akschoeck

    (@akschoeck)

    So I got the action hooked correctly, and the function is being called when I want it to. (Tested with the email example given here: https://codex.www.ads-software.com/Function_Reference/add_action, and I am receiving an email when updating the job post)

    However, I am having more trouble with building the function than I thought. I cannot get the wp_set_post_tags function to work (https://codex.www.ads-software.com/Function_Reference/wp_set_post_tags).

    I am trying something as simple as

    function update_tournaments( $post_ID ) {     
    
    	wp_set_post_tags( 12993, '123', true );
    
       $friends = '[email protected]';
       wp_mail( $friends, $post_ID, 'test');
    
       return $post_ID;
    }
    add_action( 'job_manager_update_job_data', 'update_tournaments' );

    and it is still not working (I left the email in there for testing purposes).

    Ultimately, I am going for something along the lines of

    function update_tournaments( $post_ID ) { 
    
    	$day1 = get_custom_field ( 'tournament1_day' );
    	$day2 = get_custom_field ( 'tournament2_day' );
    	$day3 = get_custom_field ( 'tournament3_day' );
    	$tags = array($day1, $day2, $day3);
    	wp_set_post_tags( $post_ID, $tags, true );
    
       return $post_ID;
    }
    add_action( 'job_manager_update_job_data', 'update_tournaments' );

    but wanted to start with something simple. Can’t test what I’ve created if I can’t even get a the simplest version working =\

    Plugin Author Mike Jolley

    (@mikejolley)

    Thread Starter akschoeck

    (@akschoeck)

    Making baby steps with each of your suggestions, but I keep being unable to take it to the next step.

    Here’s what I’m currently trying:

    function update_tournaments( $post_ID ) {
       $day1 = get_custom_field ( 'tournament1_day' );
       $day2 = get_custom_field ( 'tournament2_day' );
       $day3 = get_custom_field ( 'tournament3_day' );
       $tags = array($day1, $day2, $day3);
    
       wp_set_post_terms( $post_ID, $tags, 'job_listing_tag', false );
    
       return $post_ID;
    }
    add_action( 'job_manager_update_job_data', 'update_tournaments' );

    Also tried using

    get_post_meta($post_ID, "tournament1_day", true); instead of get_custom_field

    but that also did not work.

    It successfully updates the post’s tags if I have the variable $tags set to an array of strings such as $tags = 'hello, goodbye'. So I believe at this point my last issue is figuring out how to identify the $tags as the proper custom fields.

    Plugin Author Mike Jolley

    (@mikejolley)

    How about:

    $day1 = get_post_meta( $post_ID, 'tournament1_day', true );

    OR:

    $day1 = get_post_meta( $post_ID, '_tournament1_day', true );
    Thread Starter akschoeck

    (@akschoeck)

    This one worked:

    $day1 = get_post_meta( $post_ID, '_tournament1_day', true );

    Thanks so much! Working like a charm now!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add tags to post on job add/edit submission’ is closed to new replies.