Creating a post and setting category on it

Home Forums Quform WordPress Creating a post and setting category on it

This topic is: not resolved
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #30403

    In theory that is explained here
    but what I want is a little different.
    add_filter('quform_post_process_1', function (array $result, Quform_Form $form) { $title = $form->getValue('quform_1_3'); $content = $form->getValue('quform_1_4');
    $post = array(
    'post_title' => $title,
    'post_content' => $content,
    'post_type' => 'post',
    'post_status' => 'publish'

    $postId = wp_insert_post($post);
    wp_set_object_terms($postId, 'my_category_slug', 'category');
    return $result
    }, 10, 2);

    Hope the formatting comes out right…
    Your example above assumes I would already know the category for the post,(the “my category slug” line), but I don’t. What I want is to be able to select the category from a list (select, or maybe a list of checkboxes) populated from the categories (post taxonomies) that already exist. How would I do that? Also from what I recall each post type has its own taxonomies, so if I’m looking to create a custom post type, what would the code look like?


    Um, notice me senpai? 😀 I realize this was posted during the winter holidays, but we’re now well into the new year… Even a “we’re swamped with work”, but “we ‘ll get to it” would be fine.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2019 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy