New
PeoplePress is here. Community building for WordPress, reimagined. Fast, modern, and built for the communities you've always wanted to run.
See it live

BuddyDev

Search

Passing Custom Taxonomy Multiselector values to tax_input args of wp_insert_post

  • Participant
    Level: Enlightened
    Posts: 71
    Lefteris on #47867

    Hello all 🙂

    I am using 2 Custom Taxonomy Multiselector xprofile fields to pass the values (selected categories and selected tags) from a CPT into a new post with the use of wp_insert_post.

    I have 2 taxonomies event_tag and event_category from the CPT.

    `
    $post_cat_data = (array) xprofile_get_field_data( ‘EVENT CATEGORIES’ ,$user_id );
    $post_tag_data = (array) xprofile_get_field_data( ‘EVENT TAGS’ ,$user_id );

    $args = array(
    //more args…
    ‘post_type’ => ‘event’,
    ‘tax_input’ => array(
    ‘event_category’ => $post_cat_data,
    ‘event_tag’ => $post_tag_data,
    ),
    );

    $ID = wp_insert_post( $args );

    `

    $post_tag_data are passing correct to tax_input but $post_cat_data are not.
    I have tried also $post_cat_data = xprofile_get_field_data( 'EVENT CATEGORIES' ,$user_id, 'array' ); but it didn’t work. Any ideas would be appreciated.

  • Participant
    Level: Enlightened
    Posts: 71
    Lefteris on #47868

    The results that i am getting from the the 2 fields with var_dump are:

    for EVENT CATEGORIES

    <pre>array(2) {
      [0]=>
      string(164) "<ul class="bpxcftr-multi-taxonomy-terms-list"><li><a href="">Walk</a></li></ul>"
      [1]=>
      string(152) "<ul class="bpxcftr-multi-taxonomy-terms-list"><li><a href="">Dance</a></li></ul>"
    }
    </pre>

    for EVENT TAGS

    <pre>array(3) {
      [0]=>
      string(128) "<ul class="bpxcftr-multi-taxonomy-terms-list"><li><a href="">Speak</a></li></ul>"
      [1]=>
      string(144) "<ul class="bpxcftr-multi-taxonomy-terms-list"><li><a href="">Read</a></li></ul>"
      [2]=>
      string(128) "<ul class="bpxcftr-multi-taxonomy-terms-list"><li><a href="">Think</a></li></ul>"
    }
    </pre>

    So the results looks the same.

  • Keymaster
    (BuddyDev Team)
    Posts: 25509
    Brajesh Singh on #47877

    Hi,
    You are accessing the formatted value for display.

    Please use the raw value using

    
    
    $values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field_id, $user_id ) );
    
    

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved