This one has been bothering me for a few days now, so I'd really appreciate any help you can give me.
Problem overview:
I have a plugin which automatically creates a post and assigns the category "YouTube" whenever a new video is uploaded to a YouTube channel. This part works fine. However - I'm also wanting the post to be assigned the post type "Video". The plugin doesn't allow for this type of customisation, so this will have to be done in php.
Where I've looked: (included for those who like to say "Have you read the forums?")
WordPress Codex Set Post Format
What I've tried:
A few different attempts aren't getting me any results (not white screen of deathing me either so that's a bonus?)
1: (not sure where I'd need to tell that function to run)
//* If post has category YouTube - set post type to video
function default_post_type($post_id) {
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
if (in_category('YouTube')) {
set_post_format($post_id, 'video');
}
}
}
2: (mixing it up a little bit, because ... reasons?)
//* If post has category YouTube - set post type to video
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
function default_post_type($post_id) {
if (in_category('YouTube')) {
set_post_format($post_id, 'video');
}
}
}
3: (so then I thought "Why even use a function at all?")
//* If post has category YouTube - set post type to video
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
if (in_category('YouTube', $post_id)) {
set_post_format($post_id, 'video');
}
}
Appreciate any help - even if you can tell me why what I've done is wrong. Thanks.
Aucun commentaire:
Enregistrer un commentaire