• Resolved mallorcagirl76

    (@mallorcagirl76)


    Hi,

    I wanna create the post title of postings of my pod from a field (text field) in the pod.

    Coukd anybody tell me how to do this ?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @mallorcagirl76

    Can you elaborate?
    Why not just use the post title field?

    Cheers, Jory

    Thread Starter mallorcagirl76

    (@mallorcagirl76)

    If you mean the original post title field built in in wordpress because of the reason that I wanna generate the post title from the value of 3 fields in my pod.

    Like example:

    First Pod field: value= Girl
    Second Pod field: value= Boy
    Third Pod field: value = Big Love

    Reslut ind post_title should be: Girl + Boy = Big Love

    Plugin Author Jory Hogeveen

    (@keraweb)

    Thread Starter mallorcagirl76

    (@mallorcagirl76)

    If I post this code into the functions.php of my theme I get an critical error !
    Solved my fault…sorry

    Thread Starter mallorcagirl76

    (@mallorcagirl76)

    I did yll like in the description. Now I have an only redable field but how I can get now this what I wrote above ? Dont check it

    Thread Starter mallorcagirl76

    (@mallorcagirl76)

    Ok its function now. Post Type was to edit for my post type.
    BUT…Now its dowing the authors name and the date as title.
    How can I get the title from three of my fields ?

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @mallorcagirl76

    You’ll have to modify the example code to use your custom fields.
    The link simply provides an example use-case. You can fetch the field data yourself and create the title string you want.

    Another example can be found here:
    https://docs.pods.io/code-snippets/create-post-title-from-fields-in-the-post-using-pods_api_pre_save/

    Cheers, Jory

    Thread Starter mallorcagirl76

    (@mallorcagirl76)

    I did it like this but I get an critical WP error:

    add_filter( 'pods_api_pre_save_pod_item_release', 'slug_set_title', 10, 2);
    function slug_set_title($pieces, $is_new_item) {
        //check if is new item, if not return $pieces without making any changes
        if ( ! $is_new_item ) {
            return $pieces;
        }
        //make sure that all three fields are active
        $fields = array( 'post_title', 'artist', 'featuring_artist' );
        foreach( $fields as $field ) {
            if ( ! isset( $pieces[ 'fields_active' ][ $field ] ) ) {
                array_push ($pieces[ 'fields_active' ], $field );
            }
        }
        //set variables for fields empty first for saftey's sake
        $artist = $featuring_artist = '';
        //get value of "artist" if possible
        if ( isset( $pieces[ 'fields' ][ 'artist' ] ) && isset( $pieces[ 'fields'][ 'artist' ][ 'value' ] ) && is_string( $pieces[ 'fields' ][ 'artist' ][ 'value' ] ) ) {
            $artist = $pieces[ 'fields' ][ 'artist' ][ 'value' ]
        }
        //get value of "featuring_artist" if possible
        if ( isset( $pieces[ 'fields' ][ 'featuring_artist' ] ) && isset( $pieces[ 'fields'][ 'featuring_artist' ][ 'value' ] ) && is_string( $pieces[ 'fields' ][ 'featuring_artist' ][ 'value' ] ) ) {
            $featuring_artist = $pieces[ 'fields' ][ 'featuring_artist' ][ 'value' ]
        }
        //set post title using $artist and $featuring_artist
        $pieces[ 'object_fields' ][ 'post_title' ][ 'value' ] = $artist . ' and ' . $featuring_artist;
        //return $pieces to save
        return $pieces;
    }
    Thread Starter mallorcagirl76

    (@mallorcagirl76)

    If i do php checker it says: “PHP Syntax Check: Parse error: syntax error, unexpected ‘}’ in your code on line 20”

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @mallorcagirl76

    Then you should check line 20 ??
    It seems you are missing semocolons (;) at the end of some lines.

    Cheers, Jory

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Post Title from value of PODS field’ is closed to new replies.