Home Trying to loop advanced custom fields pro functions .php
Reply: 1

Trying to loop advanced custom fields pro functions .php

rogue1nib
1#
rogue1nib Published in 2017-12-07 22:39:38Z

I am using Advanced Custom Fields with wordpress but I am having an issue getting it to work with creating a short code. I want to drive my team-member post type with a short code that I Can add into visual composer but I am getting an error this is what I have tried.

function team(){ 


   // get posts
   $posts = get_posts(array(
    'post_type'         => 'team-member'

   ));


     if( $posts ): ?>
<?php foreach( $posts as $post ): 
   setup_postdata( $post );       

  $description = get_field('description');
  $name = get_field('name');  

  ' i want to loop here to print out every team member 

    $cnt='';
    $cnt.='<sction class="row ev-home-4">';
        $cnt.='<div class="col-sm-12 owl-carousel owl-theme" id="teams">';
            $cnt.=' <div class="item ev-home-4-block">
                        <div class="col-sm-12 ev-home-4-block-1">
                            <img src="'.get_site_url().'/wp-content/uploads/2017/11/test-1.png" class="img-responsive">
                            <div class="row row2 ev-home-4-block-2">
                                <h2>'.$name.'</h2>
                                <small>'.$description.'</small>
                            </div>
                        </div>
                    </div>';




        $cnt.='</div>';
    $cnt.='</sction>';

    <?php endif; ?>
<?php endforeach; ?>
    return $cnt;
}
add_shortcode('team','team');

But I am getting the following error

https://preview.ibb.co/iJsi5G/chrome_2017_12_07_22_37_54.png

Stender
2#
Stender Reply to 2017-12-08 07:57:12Z

Maybe something like :

function team() {
$args = array('post_type' => 'team-member');
$return_string ="";
$the_query = new WP_Query( $args );
    while ( $the_query->have_posts() ) : $the_query->the_post();
        $return_string .= 'Your html/images etc here here';
    endwhile;
wp_reset_postdata();
return $return_string;
}

add_shortcode( 'yourShortCodeNameHere', 'team' );
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309326 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO