Can’t programmatically add category to event in plugin
(There’s another thread about this that the author did not follow up on, but I’ve discovered the same problem.) When programmatically creating an event and adding a category, the category is added when the code is run from my theme’s functions.php, but it is not added when the code is run in my plugin. This is on a test site using the 2024 theme with only Events Calendar and Event Tickets plugins (plus my plugin) running.
Here’s my minimal test code. This block creates the event and adds the category when it is run from functions.php. It creates the event but does not add the category when run in a plugin (in a cron event). I’ve tried inputting the category ID as an int and as a string. I’ve triple-checked that the category ID does already exist. Is this a bug?
function test_create_event() {
$args = array(
'post_title' => 'Test Event',
'post_content' => 'Test description',
'post_status' => 'publish',
'venue' => 61,
'show_map' => true,
'start_date' => gmdate( 'Y-m-d H:i:s' ),
'end_date' => gmdate( 'Y-m-d H:i:s', strtotime( '+2 hours' ) ),
'category' => array( 9 ),
);
$result = tribe_events()->set_args( $args )->create();
}
مشاهده پاسخ های این مطلب
———————————————
این مطلب از سایت انجمن وردپرس گردآوری شده است و کلیه حقوق مطلق به انجمن وردپرس می باشد در صورت مغایرت و یا بروز مشکل اطلاع دهید تا حذف گردد
منبع: انجمن وردپرس