user3559298
user3559298

Reputation: 77

Advance Custom Fields - All fields from one field group in one frontent array?

I must stres out that i’m not a developer so i might use some “unsupported” terms :).

Ok the issue, i have created custom post type called Firm. Also i have created field group with 7 fields (text fields mainly, including website URL field and Google map field) and i have made template that displays those fields on frontend page. Once it’s saved all data is saved in database and new post under post type Firm is created. So that all works great. The main problem/question is:

How can i display all new posts in that post type (Firm) on one page? I know i must create some loop, array for those posts, but as i said i’m not developer so i’m kind of stuck with this one.

If someone could give me a hint or some link, or any kind of pointers so i could figure out in what direction to go. Thanks in advance for your answers.

Upvotes: 1

Views: 169

Answers (3)

user3559298
user3559298

Reputation: 77

Ok this is what i have at the end, and it's working.

<?php
                    $args = array( 'post_type' => 'company', 'posts_per_page' => 15 );
                    $loop = new WP_Query( $args );
                    while ( $loop->have_posts() ) : $loop->the_post(); ?>
                    <div class="boxy">
                    <div class="acf_company_name">
                    <h5>Company Name: </h5>
                    <p><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_field('company_name'); ?></a></p>
                    </div>
                    <div class="acf_full_name">
                    <h5>Full Name: </h5>
                    <?php the_field('full_name'); ?>
                    </div>
                    <div class="acf_vat">
                    <h5>VAT: </h5>
                    <?php the_field('vat'); ?>
                    </div>
                    <div class="acf_email">
                    <h5>E-mail: </h5>
                    <a href="mailto:<?php the_field('email'); ?>"><?php the_field('email'); ?></a>
                    </div>
                    <div class="acf_website">
                    <h5>Official website: </h5>
                    <?php the_field('website'); ?>
                    </div>
                    <?php if ( get_field('logo_company') ) : ?>
                    <div class="acf_logo_company"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php $image = get_field(logo_company); ?>

                    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /></a></div>
                    <?php endif; ?>

                    <div class="acf_company_location"><?php $location = get_field('company_location');?>

                    <div class="acf-map">
                        <div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>" data-lng="<?php echo $location['address']; ?>"></div>
                    </div></div>
                    <div class="acf_company_location">
                    <h5>Company location: </h5>
                    <?php the_field('company_location'); ?>
                    </div>
                    </div>
                    <?php endwhile; ?>

Upvotes: 0

user3559298
user3559298

Reputation: 77

Ok thanks so far, thank you @Arun, i have come up with this:

<?php
                    $args = array( 'post_type' => 'company', 'posts_per_page' => 10 );
                    $loop = new WP_Query( $args );
                    while ( $loop->have_posts() ) : $loop->the_post();
                      the_title();
                      echo '<div class="entry-content">';
                      echo '<p>' . '<span>Official Wesite</span>' . '<span> : </span>' . get_field('web_site') . '</p>';
                      echo '</div>';
                     endwhile; ?>

                    <?php 

                    $location = get_field('location');

                    if( !empty($location) ):
                    ?>
                    <div class="acf-map">
                        <div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>
                    </div>
                    <?php endif; ?>

So im strugling now with how to incorporate this google map in loop. I do have title and website link for all posts but i need to have maps for each post as well.

Upvotes: 0

Arun
Arun

Reputation: 364

You can refer Wordpress Codex.

Check sample code given below

$args = array( 'post_type' => 'product', 'posts_per_page' => 10 ); // for more parameter check link http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
  the_title();
  // Displays Advanced custom field value
  the_field('field-name');
  echo '<div class="entry-content">';
  the_content();
  echo '</div>';
endwhile;

Upvotes: 1

Related Questions