• Resolved adatfalo

    (@adatfalo)


    Hi!

    How can I save POST’S CUSTOM TAXONOMY(Category) as Post Title in Post action?
    Printscreen
    I made a custom category with CPT UI [ugyfelek]. And I would like to setup the post action which saves the title like this: {field:palyazo_nev} – {post:post_title} – {THE SELECTED TAXONOMY}

    I didn’t found a working method in Cheatsheet. What am I doing wrong?

    Thanks,

    Zoltan

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    The {term} Template Tag in the ACFE Form should be used when the form is displayed on a Taxonomy Term page on the front-end. In your case, you’ll have to use the acfe/form/submit/post_args hook (See documentation) in order to retrieve the current post terms, and add it to the Post Title.

    Here is a usage example:

    add_filter('acfe/form/submit/post_args/form=my-form', 'my_form_post_args', 10, 4);
    function my_form_post_args($args, $type, $form, $action){
        
        // retrieve the current post id (where the form is being displayed)
        $post_id = $form['post_id'];
        
        // retrieve the field input value 'palyazo_nev'
        $palyazo_nev = get_field('palyazo_nev');
        
        // retrieve the current post title
        $post_title = get_the_title($post_id);
        
        // retrieve the current post category
        $category = get_the_terms($post_id, 'category');
        $category = array_shift($category);
        
        // change the post title
        $args['post_title'] = "{$palyazo_nev} - {$post_title} - {$category->name}";
        
        // return
        return $args;
        
    }
    

    Hope it helps!

    Have a nice day!

    Regards.

    Thread Starter adatfalo

    (@adatfalo)

    Hello!

    Thank you, it was helpful.
    I have one other problem.
    I use two post action. I save the form’s datas to two CPT (for different purposes).
    The my_form_post_args function is overwrite both post titles. But I would like to use it only for ‘palyazatok’.

    Can you help me to achive this?

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Sorry for the late answer, but I didn’t see your reply earlier.

    When using two Post Action within the same form, you should use hooks that target an Action Name. You can set the names in each Action. See screenshot.

    Once the name is set, then you can use named hooks like that: acfe/form/submit/post/action=my-action.

    Hope it helps!

    Have a nice day!

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post action – Save post taxonomy’ is closed to new replies.