• Resolved One234

    (@one234)


    I have a WP User Frontend Plugin, so users can post via frontend.
    Additionaly I have a custom taxonomy called board which is hierarchical.

    I have found “WPUF Action Hook Taxonomy” for my problem https://gist.github.com/tareq1988/809ed96eaaf0ce5480e0

    I can post successfully, but the choosen taxonomy from the dropdown will not be set. I checked the DB Table “wp_term_relationships”, there is no entry.

    Seems like wp_set_post_terms is not working here and I dont know why. I already tried wp_set_object_terms with no success.

    **Own_functions.php**

        /**
        * Add the input field to the form
        *
        * @param int $form_id
        * @param null|int $post_id
        * @param array $form_settings
        */
        
        function prefix_render_board_field( $form_id, $post_id, $form_settings ) {
            $selected = 0;
            if ( $post_id ) {
                $terms    = wp_get_post_terms( $post_id, 'board', array( 'fields' => 'ids' ) );
                $selected = ( is_array( $terms ) && count( $terms ) ) ? $terms['0'] : 0;
            }
            ?>
        
            <div class="wpuf-label">
                <label><?php _e( 'board', 'wpuf' ); ?></label>
            </div>
        
            <div class="wpuf-fields">
                <?php 
                $user_id = get_current_user_id();
        
                $board_parent_id = get_user_meta($user_id, "_Board Parent ID", true);
        
                wp_dropdown_categories( array(
                    'show_option_none' => __( '- Select - ', 'wpuf' ),
                    'taxonomy'         => 'board',
                    'hide_empty'       => false,
                    'name'             => 'board',
                    'hierarchical'       => 1,
                    'child_of'         =>$board_parent_id,
                    'selected'         => $selected
        
                ) ); ?>
            </div>
            <?php
    
        }
        add_action( 'my_awesome_hook', 'prefix_render_board_field', 10, 3 );
        
        /**
         * Update the custom field when the form submits
         *
         * @param type $post_id
         */
        function prefix_update_board_field( $post_id ) {
            if ( isset( $_POST['board'] ) ) {
                wp_set_post_terms( $post_id, $_POST['board'], 'board' );
            }
        }
        add_action( 'wpuf_add_post_after_insert', 'prefix_update_board_field' );
        add_action( 'wpuf_edit_post_after_update', 'prefix_update_board_field' );

    I am calling these hooks in the form:

       my_awesome_hook
        wpuf_edit_post_after_update
        wpuf_add_post_after_insert

    Does anybody have a hint for me?

    TIA

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author weDevs

    (@wedevs)

    @one234, We apologize for not getting back sooner.

    Have you resolved the issue? If not just let us know. We will be happy to help you.

    Thank you

    Plugin Author weDevs

    (@wedevs)

    @one234, We have not heard back from you in last 7 days. I am just curious if your issue is resolved. Please let me know the current situation.

    Thanks

    • This reply was modified 7 years, 1 month ago by weDevs.
    • This reply was modified 7 years, 1 month ago by weDevs.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_set_post_terms doesnt work for WPUF’ is closed to new replies.