-1

I post to Wordpress via IFTTT triggers; however, all of my posts go into the default category set up within Wordpress. Is there any method or plugin that would review new post and then based on a preset condition move it to the desired category.

For example, if I sent a post which had Video - My New Video, it would look for the prefix Video and move the post to a category called Video etc. Thanks John

2

I doubt there are any plugins out there that can do what you want "out-of-the-box", however you could probably write a plugin to do what you're looking for. Some basic boilerplate logic could look like

function jcharnock_insert_post_category( $post_id, $post, $update ) {
    // Only run on inserts.
    if ( $update ) {
        return;
    }

    $title_categories = array(
        'video',
        'image',
    );

    // See if the category is the first word in the title, use a delimiter for safety.
    foreach ( $title_categories as $cat ) {
        if ( 0 === stripos( $post->post_title, "{$cat} - " ) ) {
            wp_set_object_terms( $post_id, $cat, 'category', false );
        }
    }
}

add_action( 'wp_insert_post', 'jcharnock_insert_post_category', 10, 3 );

What does this do?

With this action in place, if you were to send a post to your site named "Video - My new cool video post" or "Image - Some image post", the new posts would be assigned the respective category of 'video' or 'image'.

Title categories are delimited with a - (space-dash-space) so that other posts don't accidentally get miscategorized, such as "Video players that are awesome" or "Image software reviews".Of course, you can make that delimiter whatever you want, or not use it at all, it's just to help minimize mistakes.

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.