0

Currently I have created a custom taxonomy with the name "genre" and I am wondering how I can include it into the array for posting with the content from the string provided in the example.

$my_post = array(
  'post_title'    => wp_strip_all_tags( trim( $post_title ) ),
  'post_content'  => $my_post,
  'post_status'   => 'publish',
  'post_author'   => 2,
  'post_category' => array( 2 ),
  'the_taxonomy' => $v['artist']['name'],
  'post_date' => date('Y-m-d H:i:s')
);

The custom taxnomy I am currently using can be seen below.

add_action( 'init', 'create_genre_nonhierarchical_taxonomy', 0 );

function create_topics_nonhierarchical_taxonomy() {


$labels = array(
  'name' => _x( 'Genre', 'taxonomy general name' ),
  'singular_name' => _x( 'Genre', 'taxonomy singular name' ),
  'search_items' =>  __( 'Search Genre' ),
  'popular_items' => __( 'Popular Genre' ),
  'all_items' => __( 'All Genre' ),
  'parent_item' => null,
  'parent_item_colon' => null,
  'edit_item' => __( 'Edit Genre' ), 
  'update_item' => __( 'Update Genre' ),
  'add_new_item' => __( 'Add New Genre' ),
  'new_item_name' => __( 'New Genre Name' ),
  'separate_items_with_commas' => __( 'Separate topics with commas' ),
  'add_or_remove_items' => __( 'Add or remove topics' ),
  'choose_from_most_used' => __( 'Choose from the most used topics' ),
  'menu_name' => __( 'Genre' ),
); 

register_taxonomy('topics','post',array(
  'hierarchical' => false,
  'labels' => $labels,
  'show_ui' => true,
  'show_admin_column' => true,
  'update_count_callback' => '_update_post_term_count',
  'query_var' => true,
  'rewrite' => array( 'slug' => 'topic' ),
));
}

Any help is very much appreciated

  • I do not know what you're asking. Could you explain in different terms what you're trying to do? – Howdy_McGee Oct 28 '15 at 21:11
  • @Howdy_McGee You see where I have the taxonomy in the first portion? It's not displaying anything the Taxonomy's name is "Genre" how can I make it display the contents from the string provided. – Ritzy Oct 28 '15 at 21:20
  • I'm still not sure what you're asking. What is $v? Where is it being populated? the_taxonomy isn't a valid parameter to any post args I know of so I'm assuming this is just a custom array. Is $v['artist']['name'] supposed to hold some kind of term content? – Howdy_McGee Oct 28 '15 at 21:23
  • @Howdy_McGee The content in that string is not important it just holds the artist name for that post, I am trying to figure out the way to put this into the array how ever.. I am sorry if I am being very confusing I'm trying to explain in the best way I can. – Ritzy Oct 28 '15 at 21:25
1

Your question is confusing but assuming that you want your array to be an argument set for, say, wp_insert_post() then...

I am wondering how I can include it into the array for posting with the content from the string provided in the example.

... you need tax_input. I am pretty sure I've got this right:

$my_post = array(
  'post_title'    => wp_strip_all_tags( trim( $post_title ) ),
  'post_content'  => $my_post,
  'post_status'   => 'publish',
  'post_author'   => 2,
  'post_category' => array( 2 ),
  'tax_input' => array(
    'genre' => 'abcdefg',
  ),
  'post_date' => date('Y-m-d H:i:s')
);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.