Support

Account

Home Forums ACF PRO Post_object fields in vCard

Solving

Post_object fields in vCard

  • After successfully building dynamic profile pages, after the fact, I am trying to add a vCard generated dynamically from each Personnel Profiles. Everything is working with exception of rendering the address.

    The address is drawn from fields on a post_object related to the personnel profile. I am able to render them in the actual profile page but not able to figure the code to render then in the vCard function.

    The code below does render the post_object id (ex. value post_id- 591) but I have not been able to add my ACF Pro custom fields from the post_object as they are in each post, EX:

    Example profile page

    <?php
    
    if( isset($_GET['vcard']) ) {
    global $post;
    
    $custom = get_post_custom($post->ID);
    
    header('Content-type: text/x-vcard; charset=utf-8');
    header('Content-Disposition: attachment; filename="vcard.vcf"');
    
    echo "BEGIN:VCARD\n";
    echo "VERSION:2.1\n";
    echo 'N:'.$custom["LastName"][0]. ',' .$custom["FirstName"][0]."\n";
    echo 'FN:' .$custom["FirstName"][0] .' '.$custom["middle"][0] .' '.$custom["LastName"][0]."\n";
    echo "ORG:Brock and Scott PLLC\n";
    echo 'TITLE:'.$custom["job_title"][0]."\n";
    echo 'TEL;WORK;VOICE:'.$custom["Phone"][0]."\n";
    echo 'EMAIL;PREF;INTERNET:'.$custom["Email"][0]."\n";
    echo 'ADR;PREF;WORK:'.$custom["location"][0]."\n";
    /// etc for each field
    echo "END:VCARD\n";
    exit();
    }
    
    get_header(); ?>

    Each of the other fields are also ACF custom fields from the profile loop and are simply echo’d as above. Is there a way to add these sub fields from the post_object in the vCard code.

  • I’m missing which fields you’re struggling with and why ?

  • I’m sorry this was not a good description.

    I need the Address field(s).

    In each profile page, all the correctly rendering fields; Name, Company Name, Title, email and Phone number are pulled directly from personnel post type custom fields. However, The address fields are brought in from a post_object in a Custom Post Type of Locations. In the loop that looks like:

    <?php $field_name = "location";
    $field = get_field_object($field_name);
    echo $field['label']; ?>:</h5>
    	<?php $post_object = get_field('location'); 
    	if( $post_object ): 
    		// override $post
    		$post = $post_object;
    		setup_postdata( $post ); ?>
    		<p><?php the_field('street_address'); ?><br>
    		<?php the_field('suite_office'); ?><br>
    		<?php the_field('city'); ?>, <?php the_field('state'); ?><?php the_field('zip_code'); ?>

    I having trouble getting ; street_address, suite_office, city and state to render in the vCard.

    To be specific, I don’t know how to render the post object and related subfields into the vCard ‘echo’ statement. Does that make more sense?

  • I don’t quite know what the vcard syntax is, but you cn find that somewhere else.

    Looking at your code, I would do it as follows:

    $field = get_field_object("location");
    echo "<h5>" . $field['label'] . "</h5>";
    $post_object = get_field('location'); 
    if ( $post_object ) : 
    ?>
        <p><?php the_field('street_address', $post_object->ID); ?><br>
        <?php the_field('suite_office', $post_object->ID); ?><br>
        <?php the_field('city', $post_object->ID); ?>, <?php the_field('state', $post_object->ID); ?><?php the_field('zip_code', $post_object->ID); ?>
  • Hi,

    Im trying to do like this but how do I write the code for download the vCard file?

    I want to generate a vCard from ACF fields and then make it possible to download the vcard.

  • @treon This is not an ACF question, so check here http://bfy.tw/Mqq4

  • What is not connected to ACF with this subject you mean? If you don’t want to help then please do not write.

  • As you can see I have already offered help to the person who created the thread but a Vcard is NOT an ACF feature.

    And the OP already posted the format, so you’re not reading the topic.

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Post_object fields in vCard’ is closed to new replies.