• Resolved Jess Boctor

    (@phantomblonde)


    Okay, I have been beating my head against this for awhile now.

    I am using the Advanced Custom Fields plugin to create custom fields for some custom post types I created. A lot of information needs to pass from one custom post type to the next. What I am working on right now is creating a title from a combination of two other post titles which the user selects in the custom fields.

    IE: Select 1 – Select 2 Title

    I have the code to do this, and I can even easily pull the post ID of the posts to be used in creating the titles. Here is where I am having a problem, and it may just be that I am too new at php. I want to use get_the_title(); to display the two titles. Currently, my code looks like this:

    <?php
    $sa_customer_id = the_field('sa_customer'); /* Sets variable to post ID number, ie echo $da_customer_id writes 130*/
    $sa_site_id = the_field('sa_site');
    
    get_the_title($sa_customer_id) . " - " . get_the_title($sa_site_id) . " Audit"; ?>

    The title displays correctly when I manually place in the post ID’s, but defaults when I use the variables. I realize now, I need to create an object for the variables, but I am at a loss for how to do this. Any help or suggestions would be greatly appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Jess Boctor

    (@phantomblonde)

    Nevermind! I figured out a work around using get_post();

    $sa_customer_id = get_field('sa_customer');
    
    $customer_id = get_post($sa_customer_id);
    $customer_title = $customer_id->post_title;
    
    $sa_site_id = get_field('sa_site');
    
    $site_id = get_post($sa_site_id);
    $site_title = $site_id->post_title;
    ?>
    <h1><?php echo $customer_title . " - " . $site_title . " Audit"; ?></h1>

    It’s not so pretty yet, but it works and I can clean it up as I go along. ??

    Thread Starter Jess Boctor

    (@phantomblonde)

    Closing this out as resolved.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change Variable to object for get_the_title()p’ is closed to new replies.