I
I
Ivseti2021-03-22 14:11:30
WordPress
Ivseti, 2021-03-22 14:11:30

Advanced Custom Fields how to display phone number in widget with div wrapper?

Advanced Custom Fields how to display phone number in widget with div wrapper?

In the widget code, a regular phone is displayed like this:

<?php if ( $myhome_estate->agent->has_phone() ) : ?>
                        <div class="mh-estate__details__phone">
                            <a href="tel:<?php echo esc_attr( $myhome_estate->agent->get_phone_href() ); ?>">
                                <i class="flaticon-phone"></i> <?php echo esc_html( $myhome_estate->agent->get_phone() ); ?>
                            </a>
                        </div>
          <?php endif; ?>


In the module settings I set Text and value:
User groups equal to All

As written in the documentation, the output does not work:
<h2><?php the_field('heading'); ?></h2>

This method also does not work:
$term = get_queried_object();
$my_gallery = get_field('my_gallery', $term);
echo do_shortcode($my_gallery);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Litvinenko, 2021-03-22
@Ivseti

This is how I deduced for authors
Display a group of fields if the User is equal to All

<?php

  $args = array(
    'role__in'     => array( 'administrator', 'author', 'editor' ),
    'orderby'      => 'display_name',
    'order'        => 'ASC',
    'number'       => '6',
  );

  $authors = get_users( $args );

?>

<?php foreach ( $authors as $author ) : 
  $user_id = $author->ID;
  $phone_number = get_field('user_phone', 'user_'. $user_id);
  $phone_number_trimmed = preg_replace("/[^0-9]/", '', $phone_number);
?>
  <article class="author">

    <?php if ( $phone_number ) : ?>
      <a href="<?php echo $phone_number_trimmed ?>" class="user-phone"><?php echo $phone_number ?></a>
    <?php endif ?>

  </article>
<?php endforeach; ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question