Support

Account

Forum Replies Created

  • Perfect, thank you.
    This code should really be added to the acf example page.
    https://www.advancedcustomfields.com/resources/google-map/

    I think in most use cases users would only want a single infowindow open at a time.


    @acf-support

  • Yeah, unfortunately none of those methods seem to work in the post edit page.

    However I did figure it out by looking through some other gutenberg examples:

    $post_id = get_the_ID() ? get_the_ID() : $_POST['post_id'];

  • Hi @shawnrosspeters

    Just unset the two header lines in the main function. That is the cause of the problem.

    //header('Content-type: text/x-vcard; charset=utf-8');
    //header("Content-Disposition: attachment; filename=".$filename);
  • Nevermind, just figured it out. Not actually out yet correct?

    I think I got the wrong impression from this article:

    https://wptavern.com/acf-5-0-released-with-updated-ui-and-gutenberg-compatibility

  • I should mention what I am really trying to do here is have a way to display upcoming and past events separately for events that are assigned to a specific post. This seems to be working for me:

    <?php
    	$today = date( 'Ymd' );
    	$post_ids = get_field('seminars', false, false);
    
    	$posts = get_posts(array(
    		'post_type' => 'any',
    		'posts_per_page'	=> -1,
    		'post__in'	=> $post_ids,
    		'meta_key'       => 'event_date',
    		'meta_compare'   => '>=',
    		'meta_value'     => $today,
    	));
    
    	if( $posts ) {
    		?>
    		<ul>
    			<?php foreach( $posts as $post): ?>
    				<?php setup_postdata($post); ?>
    				<li class="line">
    					<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    					<?php the_excerpt(); ?>
    				</li>
    			<?php endforeach; ?>
    		</ul>
    		<?php wp_reset_postdata(); ?>
    		<?php } ?>
  • Hey @hube2

    Thanks for your help here. I am just touching back on this now. I put my repeater and date fields in the two specified areas, along with the_title in the loop area so my code looks like this:

    <?php // get relationship field without formatting
    // returns an array of post ID values
    $posts_ids = get_field('seminars', false, false);
    // do your own query to order the posts
    $args = array(
      'post_type' => 'any',
      'posts_per_page' => -1,
      'post__in' => $post_ids,
      'meta_query' => array(
        'date_clause' => array(
          'key' => 'event_time',
          'value' => 'EXISTS'
        ),
      ),
      'orderby' => array('date_clause' => 'ASC');
    );
    $custom_query = new WP_Query($args);
    if ($custom_query=>have_posts()) {
      while ($custom_query=>have_posts()) {
        $custom_query=>the_post();
        the_title();
      }
    }
    wp_reset_postdata();
    ?>

    However I get a php error at this line:
    'orderby' => array('date_clause' => 'ASC');

    [08-Oct-2018 14:29:58 UTC] PHP Parse error: syntax error, unexpected ‘;’, expecting ‘)’ in /home/clientname/public_html/wp-content/themes/mytheme/template-parts/content-attorney.php on line 182

    I’ve been playing find the syntax error with no luck. Anything glaringly obvious to you?

  • So I did end up just creating the vCard upon saving the custom post type by cobbling together a few different methods. I started with this function:

    function hj_create_vCard( $post_id ) {
    
    	/*
         * In production code, $slug should be set only once in the plugin,
         * preferably as a class property, rather than in each function that needs it.
         */
        $post_type = get_post_type($post_id);
    
        // only update the attorneys custom post type on save
        if ( "attorneys" != $post_type ) return;
    
        $vpost = get_post($post->ID);
        $filename = $vpost->post_name.".vcf";
        header('Content-type: text/x-vcard; charset=utf-8');
        header("Content-Disposition: attachment; filename=".$filename);
        $data=null;
        $data.="BEGIN:VCARD\n";
        $data.="VERSION:3.0\n";
        $data.="FN:".$vpost->post_title."\n"; // get post title
        $data.="ORG:Client Company Name\n";
        $data.="EMAIL;TYPE=work:" .get_field('att_email',$vpost->ID)."\n";  // get acf field value
        $data.="TEL;WORK;VOICE:" .get_field('att_phone',$vpost->ID)."\n";  // get acf field value
        $data.="ADR;WORK;PREF:123 Fake Street;Fake City;MN;55106\n";  // get acf field value
        $data.="END:VCARD";
        $filePath = get_template_directory()."/vcard/".$filename; // you can specify path here where you want to store file.
        $file = fopen($filePath,"w");
        fwrite($file,$data);
        fclose($file);
    }
    add_action( 'save_post', 'hj_create_vCard' );

    Then for use in my template I just grab the file that is generated on save by looking for the file based on its name, which is generated from the page slug:

    <?php
    global $post;
    $vcfname = $post->post_name;
    ?>
    
    <a href="<?php echo get_template_directory_uri(); ?>/vcard/<?php echo $vcfname; ?>.vcf"><i class="far fa-address-card"></i> Download Vcard</a>
  • Ok, after much gnashing of teeth and sighing I finally got something that worked. Immediately the problem is that wp_get_attachment_metadata is for something else. I wanted wp_get_attachment

    Function:

    function wp_get_attachment( $attachment_id ) {
    
    	$attachment = get_post( $attachment_id );
    	return array(
    		'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
    		'caption' => $attachment->post_excerpt,
    		'description' => $attachment->post_content,
    		'href' => get_permalink( $attachment->ID ),
    		'src' => $attachment->guid,
    		'title' => $attachment->post_title
    	);
    }

    Useage:

    <?php
    $attachment = wp_get_attachment( get_field( 'primary_image' ) );
    echo $attachment['caption'];
    ?>
  • Im getting nowhere on this. So frustrating

    Is caption even part of the array from wp_get_attachment_metadata?

    Because I cant get it to return it, and a var dump doesnt seem to show it:

     array(5) {
      ["width"]=>
      int(400)
      ["height"]=>
      int(300)
      ["file"]=>
      string(19) "2018/07/400x300.png"
      ["sizes"]=>
      array(3) {
        ["thumbnail"]=>
        array(4) {
          ["file"]=>
          string(19) "400x300-150x150.png"
          ["width"]=>
          int(150)
          ["height"]=>
          int(150)
          ["mime-type"]=>
          string(9) "image/png"
        }
        ["medium"]=>
        array(4) {
          ["file"]=>
          string(19) "400x300-300x225.png"
          ["width"]=>
          int(300)
          ["height"]=>
          int(225)
          ["mime-type"]=>
          string(9) "image/png"
        }
        ["square"]=>
        array(4) {
          ["file"]=>
          string(19) "400x300-300x300.png"
          ["width"]=>
          int(300)
          ["height"]=>
          int(300)
          ["mime-type"]=>
          string(9) "image/png"
        }
      }
      ["image_meta"]=>
      array(12) {
        ["aperture"]=>
        string(1) "0"
        ["credit"]=>
        string(0) ""
        ["camera"]=>
        string(0) ""
        ["caption"]=>
        string(0) ""
        ["created_timestamp"]=>
        string(1) "0"
        ["copyright"]=>
        string(0) ""
        ["focal_length"]=>
        string(1) "0"
        ["iso"]=>
        string(1) "0"
        ["shutter_speed"]=>
        string(1) "0"
        ["title"]=>
        string(0) ""
        ["orientation"]=>
        string(1) "0"
        ["keywords"]=>
        array(0) {
        }
      }
    }

    Here is the code I tried:

    <?php
    $id = get_field('primary_image');
    $img_meta = wp_get_attachment_metadata( $id );
    echo $img_meta[image_meta][caption];
    ?>
  • Where

    $uniqueid = uniqid('faq_items');

    sets a variable by pulling the ACF unique ID of a repeater in a flex block called faq_items

    and

    <div id="collapse-<?php echo esc_attr( $uniqueid ); ?>-<?php echo esc_attr( $count ); ?>

    echos that out in the frontend and also increments the repeater rows.

  • Just an FYI for more advanced usage cases, for example where you have multiple repeaters on the same page in flexible content and you need unique ID’s for each block(for example to target bootstrap modals or collapse elements) you can do something like this:

    <section class="faq-block <?php if (get_sub_field('background') == 'blue'): ?> blue-bg<?php else: ?><?php endif; ?>">
        <div class="container">
            <div class="row text-center">
                <div class="col-md-10 col-md-offset-1">
    
                    <h2 class="section-heading"><?php the_sub_field( 'section_heading' ) ?></h2>
    
                    <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                       <?php
                       //$uniqueid = get_sub_field( 'faq_unique_id' );
                       $uniqueid = uniqid('faq_items');
                       $count = 0;
                       while ( have_rows( 'faq_items' ) ) : the_row(); ?>
                       <div class="panel panel-default listbox">
                        <div class="panel-heading" role="tab" id="headingTwo">
                            <h3 class="panel-title">
                                <a data-toggle="collapse" data-parent="#accordion"
                                href="#collapse-<?php echo esc_attr( $uniqueid ); ?>-<?php echo esc_attr( $count ); ?>"
                                aria-expanded="false">
                                <?php the_sub_field( 'faq_question' ) ?>
                            </a>
                        </h3>
                    </div>
                    <div id="collapse-<?php echo esc_attr( $uniqueid ); ?>-<?php echo esc_attr( $count ); ?>"
                        class="panel-collapse collapse" role="tabpanel">
                       <div class="panel-body">
                        <p><?php the_sub_field( 'faq_answer' ) ?></p>
                    </div>
                </div>
            </div>
            <?php $count ++; ?>
    
        <?php endwhile; ?>
    
    </div><!--end panel group-->
    
    </div>
    </div>
    </div>
    </section>
  • This was way farking easier than I was making this out:

    
    <?php
                  $filter_buttons = get_sub_field('show_filter_buttons');
                  
                  foreach ( $filter_buttons as $button ) :
                  ?>
    
                  <a href="javascript:void(0)" class="btn btn-danger filter<?php echo $button['value']; ?>"><?php echo $button['label']; ?></a>
    
                <?php endforeach; ?>
Viewing 12 posts - 1 through 12 (of 12 total)