• Resolved mssbee

    (@mssbee)


    I have been through this forum and the TDO forum and the code examples are not working for me. I can make a title using one custom field with this code:

    <?php
    /* assuming you have called the custom field key "State"... */
    $post_title = get_post_meta($post_id, 'State', true);
    $postdata = array( "ID" => $post_id, "post_title" => $post_title);
    sanitize_post($postdata,"db");
    wp_update_post($postdata);
    ?>

    When I follow the coding examples in the forums and create this code
    all I get is the date and time stamp:

    <?php
    $description = get_post_meta($post_id, ‘Description’, true);
    $city = get_post_meta($post_id, 'City', true);
    $state = get_post_meta($post_id, 'State', true);
    $post_content = $description . $city. $state;
    $postdata = array(
    “ID” => $post_id,“post_title” => $post_content);
    sanitize_post($postdata,”db”);
    wp_update_post($postdata);
    ?>

    I have also tried replacing post_content with post_title.

    Any ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter mssbee

    (@mssbee)

    Well, I found out my mistake – curly quotes and changing the = to . equal

    Here is the correct code in case anyone would like to use it:

    <?php
    $description = get_post_meta($post_id, 'Description', true);
    $city = get_post_meta($post_id, 'City', true);
    $state = get_post_meta($post_id, 'State', true);
    $post_title .= $description . $city . $state;
    
    $postdata = array("ID"=> $post_id, "post_title" => $post_title);
    sanitize_post($postdata,"db");
    wp_update_post($postdata);
    ?>

    Hi

    I am wanting to do the same, and have copied your code as follows, with my 3 field name changes:

    <?php
    $name = get_post_meta($post_id, 'Name', true);
    $suburb = get_post_meta($post_id, 'Suburb', true);
    $phone = get_post_meta($post_id, 'Phone', true);
    $post_title .= $name . $suburb . $phone;
    
    $postdata = array("ID"=> $post_id, "post_title" => $post_title);
    sanitize_post($postdata,"db");
    wp_update_post($postdata);
    ?>

    My three custom fields are called:

    TDOMF Form #1 Custom Field #Name
    TDOMF Form #1 Custom Field #Suburb
    TDOMF Form #1 Custom Field #Phone

    Each attempt I make, after finding a few errors each time, have resulted in the “No Post Title” error.

    Can anyone please see what I am doing wrong ?

    I fathomed it out, I got the field names wrong.

    Where my actual field name was “TDOMF Form #1 Custom Field #Name”
    I just used the “#name” part.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: TDO Mini Forms] Title using 3 Custom Fields and Example Codes Not Working’ is closed to new replies.