• Resolved Martin ter Wee

    (@martybabes)


    I have added a hidden input field to Events Manager Event Form.

    I have added the add_filter to call em-event.php ’em_event_save’.

    Debugger shows data being posted:
    Http Request body sending:…form-data; name=”event_area” NT-Darwin

    In an mu-plugin file I have the following code …
    (other functions in the file are working fine)

    /*=========Events Manager - Save Area Tag ======================*/
    function my_em_tag_event_save($result, $EM_Event){
    if( $EM_Event->event_id && !empty($_POST['event_area']) ){
      /* set tags for post (delete existing) */
      wp_set_post_terms( $EM_Event->post_id, $tags = $_POST['event_area'], $taxonomy = EM_TAXONOMY_TAG );
      }
      return $result;
    }
    
    add_filter('em_event_save','my_em_tag_event_save',1,2);

    The tag (NT-Darwin) does not get saved – all else is working.
    Hope someone can help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    You code/function should be something like:

    add_filter('em_event_save','set_event_tags',100,2);
    function set_event_tags($result,$EM_Event){
    $tags = array();  
    if( $result ){
    wp_set_object_terms( $EM_Event->post_id, null, EM_TAXONOMY_TAG );
    foreach($_REQUEST['event_tags'] as $tagID){
    $tag= get_term_by('id', $tagID, EM_TAXONOMY_TAG );
    wp_set_object_terms( $EM_Event->post_id, $tag->term_id, EM_TAXONOMY_TAG, true ); 
    }		
    }	
    return $result;
    }
    Thread Starter Martin ter Wee

    (@martybabes)

    Thanks for your reply tim.

    I cut the code right down to this. “darwin” is an Events Manager tags slug.

    add_filter(’em_event_save’, ‘set_event_tags’, 100, 2);

    function set_event_tags($result, $EM_Event){
    wp_set_object_terms( $EM_Event->post_id, ‘darwin’, EM_TAXONOMY_TAG, false);
    return $result;
    }

    This code is in a file in the mu-plugins. I assume the hook gets fired?
    I have tried it with wp_set_post_tags as well. Either function should replace any current tags (according to WP doc), but none ever appear. As far as I can tell, I am using it correctly.

    I can add tags via the dashboard, but that is no good for the use case.

    Hello,

    It might be possible that the events tags are not properly passed on your filter? maybe wrong select/input name? I would suggest trying something like var_dump or print_r to display that data that you’re trying to pass inside wp_set_object_terms, Please do make sure that you’re also passing the correct format in https://developer.www.ads-software.com/reference/functions/wp_set_object_terms/ sometimes you thought it’s an array but the array is not properly formatted.

    Thread Starter Martin ter Wee

    (@martybabes)

    I added the following line in em-event.php
    echo file_put_contents("atest.txt","Testing em_event_save after apply_filters");
    and achieved the desired result – a file with the line.

    However, the following placed in mu-plugins/utilities.php yields no file.

    add_filter('em_event_save', 'set_event_tags', 10, 2);
    
    function set_event_tags($result, $EM_Event){
        echo file_put_contents("atest.txt","Testing em_event_save via utilities add_filter");
    	return $result;
    }

    In other words, the hook does not fire?
    Where to go from here I cannot tell, but if anyone can I will be forever grateful!

    Thread Starter Martin ter Wee

    (@martybabes)

    I found hook will work if I put the code in the templates functions.php
    Something odd with location of mu-plugins folder as I found neccessary to place
    at: wp-content/plugins/mu-plugins
    rather than default: wp-content/mu-plugins to make something else work.
    Well at least problem solved.
    To save tags wp_set_object_terms() works (using slug), but could not get it to work wp_set_post_tags.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Unable to save EM_TAXONOMY_TAG when creating an event’ is closed to new replies.