3

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:

  • Create a new standard-format post
  • Enter a url into the _format_link_url custom field
  • If the custom field is not empty, on save/update, change the post format to 'link'; else, remain 'standard'.

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);
1
  • The new WP 3.6 will very likely include a built-in UI solution for Post Formats, so you might want to develop with it instead.
    – gyo
    Commented May 8, 2013 at 8:08

1 Answer 1

0

If the plugin works the way I think it does, you could try changing the priority of your gateway_set_post_format function being added to the save_post action.

Your plugin may have a larger priority number which would make it fire later than yours.

If the plugin does not change the custom field value until after your function is run, then that could explain the current behavior.

add_action('save_post', 'gateway_set_post_format',999, 1);

I hope you get it sorted out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.