Default taxonomy with frontend submission

Support MB Frontend Submission Default taxonomy with frontend submission

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #33230
    Philip FaderlPhilip Faderl
    Participant

    Hi everyone!
    I searched everywhere for it but couldn't find it (maybe I use the wrong terms?!):
    How is it possible to define a specific default taxonomy of a custom post type which is submitted via the frontend?

    My users are submitting ideas to my roadmap. I want their posts go directly to the 'ideas' category of my overall roadmap post type. Currently they have no taxonomy assigned. I don't want to let them be able to assign a category because I want to decide on how to proceed on each category.

    A second question is if there is any possibility to upvote such posts via MetaBox Plugin?! Would be interesting to know!

    Anybody who can help me? Would be awesome!

    Best regards,
    Philip

    #33243
    Long NguyenLong Nguyen
    Moderator

    Hi Philip,

    You can use the WordPress function wp_set_post_terms() and hook to the action rwmb_frontend_after_save_post to set a post term after submitting a post on the frontend.

    Read more on the documentation https://docs.metabox.io/extensions/mb-frontend-submission/#post-actions

    Regarding the second question, Meta Box does not support upvoting posts like that.

    #33257
    Philip FaderlPhilip Faderl
    Participant

    Hi Long,
    Thanks for your response! Ok... I am currently trying to come up with some solution. Unfortunately, I am absolutely a coding beginner (to say the least).
    I'm using elementor and I wonder how to include the code? Within the shortcode or with HTML? Both didn't work when I pasted it like I show below...
    I guess I have to embed this code instead of the sole shortcode more or less like that?!?!
    <div>$form = '[mb_frontend_form id="meta-box-id" post_fields="title,content"]';
    echo do_shortcode( $form );
    do_action( 'rwmb_frontend_before_save_post', wp_set_post_terms('in-ueberlegung'));</div>
    Is there something missing? What do I have to make differently?
    Would be great to hear!
    Best regards,
    Philip

    #33268
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Here is the example code

    add_action( 'rwmb_frontend_after_save_post', function( $post ) {
        wp_set_post_terms( $post->post_id, array( 2 ), 'category' );
    } );

    You need to change the 2 to the term ID and category to the taxonomy slug on your site. You can add the code to the file functions.php in the theme/child theme folder.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.