Home › Forums › Calendar Products › Events Calendar PRO › Categories not Submitting – tribe_create_event function
- This topic has 7 replies, 2 voices, and was last updated 8 years, 10 months ago by
Shamsi.
-
AuthorPosts
-
May 12, 2017 at 3:11 am #1282840
Shamsi
ParticipantI’m using the tribe_create_event() function to create events programatically. All of the arguments are submitting OK except for categories. ‘post_category’ => array(‘cid_71645129’) is not working. Is there a way to submit events with categories using the tribe_create_event() function?
$event_data = array(
‘post_title’ => $event_title,
‘post_status’ => ‘publish’,
‘post_author’ => 1,
‘EventStartDate’ => $event_date,
‘EventEndDate’ => $event_date,
‘EventStartHour’ => $event_start_hour,
‘EventStartMinute’ => $event_start_minute,
‘EventStartMeridian’ => $event_start_meridian,
‘EventEndHour’ => $event_end_hour,
‘EventEndMinute’ => $event_end_minute,
‘EventEndMeridian’ => $event_end_meridian,
‘post_category’ => array(‘cid_71645129’)
);tribe_create_event( $event_data );
May 12, 2017 at 9:18 am #1283021Cliff
MemberHi, Shamsi.
Thanks for your detailed question. Here are a few notes:
- Please reference https://theeventscalendar.com/function/tribe_create_event/
- It refers to wp_insert_post() so please reference that as well.
- Using post_category will be the built-in WordPress categories, which do not apply to the tribe_events custom post type unless you have some custom code to do so.
- A category ID would not have letters or underscores in it, so you’re likely doing that part incorrectly as well.
- If I understand what you’re wanting, you’d need to use tax_input instead of post_category. See the examples at their documentation page.
- FYI: The Event Categories taxonomy is Tribe__Events__Main::TAXONOMY
Please let me know if you have any follow-up questions on this topic.
May 15, 2017 at 8:55 am #1283939Shamsi
ParticipantThanks for your direction, but I’m still having an issue. I’ve updated the code using ‘tax_input’ and Tribe__Events__Main::TAXONOMY as below:
$shift_data = array(
‘post_title’ => $shift_title,
‘post_content’ => $value->notes,
‘post_status’ => ‘publish’,
‘post_author’ => ‘1’,
‘EventStartDate’ => $shift_date,
‘EventEndDate’ => $shift_date,
‘EventStartHour’ => $shift_start_hour,
‘EventStartMinute’ => $shift_start_minute,
‘EventStartMeridian’ => $shift_start_meridian,
‘EventEndHour’ => $shift_end_hour,
‘EventEndMinute’ => $shift_end_minute,
‘EventEndMeridian’ => $shift_end_meridian,
‘tax_input’ =>
array(
‘taxonomy’ => Tribe__Events__Main::TAXONOMY,
‘field’ => ‘slug’,
‘terms’ => array( ‘category1’ )
)
);tribe_create_event( $shift_data );
However, I am now getting the following errors:
Notice: wp_insert_post was called incorrectly. Invalid taxonomy: taxonomy.
Notice: wp_insert_post was called incorrectly. Invalid taxonomy: field.
Notice: wp_insert_post was called incorrectly. Invalid taxonomy: terms.Perhaps I’m not sure what the valid taxonomy terms should be? I’ve been stuck on this for several days, could you please provide any further assistance?
May 16, 2017 at 1:57 pm #1284605Cliff
MemberSorry you’re having trouble with this.
You can remove ‘post_author’ because wp_insert_post() sets it to the current user, unless you want to force it to always set User ID 1 as the author.
You should reference the code snippet at https://developer.wordpress.org/reference/functions/wp_insert_post/#comment-1710 to see how to use the tax_input argument correctly.
From that example, it should be like this:
'tax_input' => array( Tribe__Events__Main::TAXONOMY => array( 13 ), ),The ‘category1’ slug might also work instead of using the Event Category ID (13 in this example).
Please let me know how this goes for you.
May 16, 2017 at 5:32 pm #1284671Shamsi
ParticipantThanks for your advice!
However, after trying the updated code as suggested, I am still having unfortunately issues.
// Create post object
$event_data = array(
‘post_title’ => ‘My post’,
‘post_content’ => ‘This is my post.’,
‘post_status’ => ‘publish’,
‘tax_input’ => array(
Tribe__Events__Main::TAXONOMY => array( ‘cid_71645129’ ),
),
‘EventStartDate’ => ‘2013-02-22’,
‘EventEndDate’ => ‘2013-02-22’,
‘EventStartHour’ => ‘2’,
‘EventStartMinute’ => ’29’,
‘EventStartMeridian’ => ‘pm’,
‘EventEndHour’ => ‘4’,
‘EventEndMinute’ => ’20’,
‘EventEndMeridian’ => ‘pm’
);$event_id = tribe_create_event( $event_data );
——————————
The result is that the Event is being posted, however, categories are still not being inserted, and WordPress is giving the following debugging messages:
Notice: Trying to get property of non-object in /wp-includes/post.php on line 3675
Notice: wp_insert_post was called incorrectly. Invalid taxonomy: tribe_events_cat. Please see Debugging in WordPress for more information. (This message was added in version 4.4.0.) in /wp-includes/functions.php on line 4138
Notice: Trying to get property of non-object in /wp-includes/link-template.php on line 49
Warning: array_keys() expects parameter 1 to be array, null given in /wp-content/plugins/the-events-calendar/src/Tribe/Linked_Posts.php on line 58
Warning: Invalid argument supplied for foreach() in /wp-content/plugins/the-events-calendar/src/Tribe/Linked_Posts.php on line 63
May 16, 2017 at 8:04 pm #1284717Cliff
MemberWhy are you using cid_71645129?
Here’s a video showing how you find the Event Category’s ID: https://cl.ly/3d3e411s0z0L
If using an actual number, as demonstrated in my video, still doesn’t work, you may need to hard-code “tribe_events_cat”, but I wouldn’t guess this is the case.
June 7, 2017 at 9:35 am #1294517Support Droid
KeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘Categories not Submitting – tribe_create_event function’ is closed to new replies.
