Custom Post Type with Custom Taxonomy

Home Forums Quform WordPress Custom Post Type with Custom Taxonomy

This topic is: resolved
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #26014
    marowi
    Participant

    Hello,

    I have a problem with submitting as custom post type with custom taxonomies.

    I have already managed to select from the existing custom taxonomy terms via “Select Menu” but the selected terms are not assigned to the custom post type after publishing.


    // Creating a custom post type
    add_filter('quform_post_process_1', function (array $result, Quform_Form $form) {
    $title = $form->getValue('quform_1_16');
    $content = $form->getValue('quform_1_14');
    $post = array(
    'post_title' => $title,
    'post_content' => $content,
    'post_type' => 'catch',
    'post_status' => 'publish'
    );
    wp_insert_post($post);
    return $result;
    }, 10, 2);


    // Adds terms from "location" to Quform
    add_action('quform_pre_display_1', function (Quform_Form $form) {
    $element = $form->getElement('quform_1_7');
    if ($element instanceof Quform_Element_Select) {
    $options = array();
    $terms = get_terms(array('taxonomy' => 'location', 'orderby' => 'count', 'fields' => 'all'));
    foreach ($terms as $term) {
    $options[] = array('label' => $term->name, 'value' => $term->slug, 'id' => $term->term_id);
    }
    $element->setOptions($options);
    }
    });

    The custom post is published but without connected taxonomies.

    Is there something I have to change in the settings?

    Best regards
    Manuel

    #26015
    marowi
    Participant

    Edit:

    When I view the entry under “Forms > Entries” I can see all selected terms.

    But they were not handed over to the published custom post type.

    #26028
    marowi
    Participant

    Problem solved. 🙂

    Here is what worked for me:


    // Creating a custom post type
    add_filter('quform_post_process_1', function (array $result, Quform_Form $form) {
    $title = $form->getValue('quform_1_16');
    $content = $form->getValue('quform_1_14');
    $location = $form->getValue('quform_1_7');
    $post = array(
    'post_title' => $title,
    'post_content' => $content,
    'post_type' => 'catch',
    'post_status' => 'publish',
    'tax_input' => $location
    );
    $post_id = wp_insert_post($post);
    wp_set_object_terms($post_id, $location, 'location');
    return $result;
    }, 10, 2);

    #26039
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

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