Advanced Custom Fields All Need Code Snippet

Advance custom field Link Field, Flexible content Field, Gallery and all need code snippet

Advance custom field Link Field, Flexible content Field, Gallery and all need code snippet

ACF Link Field Code
<?php 
$link = get_field('link');
if( $link ): 
    $link_url = $link['url'];
    $link_title = $link['title'];
    $link_target = $link['target'] ? $link['target'] : '_self';
    ?>
    <a class="button" href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>"><?php echo esc_html( $link_title ); ?></a>
<?php endif; ?>
ACF Flexible Content Field Code
<?php if( have_rows('content') ): ?>
      <?php while( have_rows('content') ): the_row(); ?>


        <!-- 1st layout start -->
        <?php if( get_row_layout() == 'layout1' ): ?>
          <div class="section">
              <?php the_sub_field('text'); ?>
          </div>
        <?php endif; ?>

        <!-- 2st layout start -->
        <?php if( get_row_layout() == 'layout2' ): ?>
          <div class="section">
              <?php the_sub_field('title'); ?>
          </div>
        <?php endif; ?>

        <!-- more will be on down  -->


      <?php endwhile; ?>
    <?php endif; ?>
ACF Image Gallery Field Code
<?php 
$images = get_field('gallery');
if( $images ): ?>
<ul>
    <?php foreach( $images as $image ): ?>
    <li>
        <a href="<?php echo esc_url($image['url']); ?>">
          <!--  
            ==================
            WP Default Image Size:
            ----------
            thumbnail(150x150),
            medium(300x300),
            medium_large(768xauto),
            large(1024x1024),
            full(original size)
            ====================== 
            -->
            <img src="<?php echo esc_url($image['sizes']['thumbnail']); ?>"
                alt="<?php echo esc_attr($image['alt']); ?>" />
        </a>
        <p><?php echo esc_html($image['caption']); ?></p>
    </li>
    <?php endforeach; ?>
</ul>
<?php endif; ?>
Active Class on first item
<?php if ( have_rows('repeter_name') ) : ?>
<!-- Assain 1 to a vairable -->
<?php $item_count = 1;?>

<ul>
    <?php while( have_rows('repeter_name') ) : the_row(); ?>

    <!-- check if it's first element then echo active class -->
    <li <?php if($item_count===1){echo 'class="active"';}?>> <?php the_sub_field('sub_field_name'); ?></li>

    <!--     
    Change the variable value with +1 from the previous value.
    So after loop it will be 2 > 3 > 4 so on.. 
    -->

    <?php $item_count++;?>
    <?php endwhile; ?>
</ul>

<?php endif; ?>
FrontEnd Form Submit Data Backend Auto Published Post Login User.
<?php
                        if(current_user_can('publish_posts')){
                        acf_form_head();
                        wp_deregister_style( 'wp-admin' );
                        //post from
                        acf_form(array(
                            'post_id' => 'new_post',
                            'field_groups' => array(295), // Used ID of the field groups url bar id here.
                            'post_title' => true, // Post Title ACF field key
                            'post_content' => true, // This will show the content field
                            'form' => true,
                            'new_post' => array(
                                'post_type' => 'post',
                                'post_status' => 'publish' // You may use other post statuses like draft, private etc.
                            ),
                            'return' => '%post_url%',
                            'submit_value' => 'Submit ❤',
                        ));
                    }else{
                        echo '<p>No Permition Post Need Help Admin  <a href="https://toofandeveloper.xyz/contact/">Contact</a> Me</p>';
                      
                    }

                    ?>
Previous Code

Add Post type to search results filtering by ACF meta value

search and filter pro tutorial,search and filter p ...

Next Code

Disable WooCommerce Payment Gateway for Specific Country WordPress

To disable a payment gateway for a specific countr ...

Leave a Reply

Your email address will not be published. Required fields are marked *

If you find it useful

buymeacoffee

ACF

Blog

Elementor

HTML JQuery

PHP

WordPress

Elementor Loop Grid Order By ACF Date Field

Create And Apply Loop Grid Template Begin by desig ...

Add Post type to search results filtering by ACF meta value

search and filter pro tutorial,search and filter p ...

top