1

I'm working with ITFFF in order to create posts, but I have a problem with the "Post Format". I need to change the Post Format to image if there are some specifics strings in the title or post content.. I was reading the forum and collecting some codes to create a this.. but it isn't working. This is my code:

add_action( 'save_post', 'CambiarPostFormat' );

function CambiarPostFormat( $postID ) {

    $a = get_the_title( $post_id );

    if ( has_post_format( 'image', $postID ) || srtpos($a, 'imagenes') !== false)
        return;
    set_post_format( $postID, 'image' );
}
1

You are using $post_id, but you have passed the post ID as $postID. As a result $a is always empty.

Even if it weren't empty, there is no PHP function srtpos. It's strpos and you could have more straightforward logic to execute set_post_format.

Wrapping it up:

function CambiarPostFormat( $postID ) {

    $a = get_the_title( $postID );

    if ( !has_post_format( 'image', $postID ) && strpos($a, 'imagenes') !== false)
      set_post_format( $postID, 'image' );
    }
1
  • Hey man, thank you so much.. It's working right now :) – Jean AL Sep 20 '16 at 17:38

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.