Site icon Hip-Hop Website Design and Development

Change post format using custom field

I’m creating a theme using the CF Post Formats plugin. But I’ve run into some trouble I don’t know how to solve. Here’s what I want to be able to do:

For whatever reason, I can’t get set_post_format to work in this context (perhaps there’s a conflicting update?). I would like things to work this way is because I want to be able to continue using Marsedit (which doesn’t support post formats) to submit content to my blog. Since Marsedit does support custom fields, I figure I can use them to auto-update the post format. Any help would be appreciated.

Update: Okay, I’ve gotten this to mostly work. It works perfectly within the admin web interface. Via the web interface, I can create a link post with a url and it saves fine. I can try changing the post to a quote post, but on updating, it reverts to a link post (as intended, for now). I can delete the url from the custom field and on update the post becomes a standard post.

However, when creating or updating a link post from Marsedit, the custom field gets as it should but the post format is set as standard. Frustrating. The function I’ve created is below. What am I missing?

function gateway_set_post_format( $post_id ) {
    $the_post_format = get_post_format( $post_id );
    if ( $the_post_format == 'link' && empty($_POST['_format_link_url'])) {
        set_post_format( $post_id, '' );
    }
    elseif ( !empty($_POST['_format_link_url']) ) {
            set_post_format( $post_id, 'link' );
    }
}
add_action('save_post', 'gateway_set_post_format',11, 1);