WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: TDO Mini Forms] Title using 3 Custom Fields and Example Codes Not Working (4 posts)

  1. mssbee
    Member
    Posted 4 years ago #

    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?

  2. mssbee
    Member
    Posted 4 years ago #

    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);
    ?>
  3. ABCDiamond
    Member
    Posted 3 years ago #

    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 ?

  4. ABCDiamond
    Member
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic