34
bit.ly/wpsydacf @leocaseiro ACF ADVANCED CUSTOM FIELDS FOR WP - 101 http://bit.ly/wpsydacf By / Leo Caseiro @leocaseiro

WordPress Advanced Custom Fields - 101

Embed Size (px)

Citation preview

bit.ly/wpsydacf

@leocaseiro

ACFADVANCED CUSTOM FIELDS FOR WP - 101

http://bit.ly/wpsydacfBy / Leo Caseiro @leocaseiro

WHY WP IS AWESOME?

NATIVE WP CUSTOM FIELDS

NATIVE WP CUSTOM FIELDS = MESS

ACF: TYPES OF FIELDS 4.4.2 (FREE)

ACF: FEATURES - VALIDATION

ACF: FEATURES - CONDITIONAL LOGIC

ACF: FEATURES - PREFIX - SUFIX - PLACEHOLDER

ACF: RELATIONAL

ACF: JQUERY - GMAPS, DATE PICKER, COLOR PICKER

ACF: NEED MORE? (EXTENSIONS)

ACF: STEP BY STEP - MOVIE DATABASE SITE

ACF: STEP BY STEP - MOVIE DB - TAB DETAILS

ACF: STEP BY STEP - CLASSIFICATION

ACF: STEP BY STEP - PREFIX, SUFIX AND PLACEHOLDER

ACF: STEP BY STEP - RELATIONAL

ACF: STEP BY STEP - CONDITIONAL LOGIC

ACF: STEP BY STEP - COUNTRY ACTOR + MOVIE

FRONTEND - DEMO https://github.com/leocaseiro/acf-movie-demo

SHOW ME SOME CODE<p><?php the_field('country'); ?></p>

<?php $subtitle = get_field('country'); echo $subtitle; ?>

<?php //get_post_meta() works, better to use the_field() and get_field() echo get_post_meta( get_the_ID(), 'country', true );?>

ACF documentation

FRONTEND - FROM DATEPICKER TO DATE I18N<?php $release_date = get_field( 'release_date' ); //Format: yyyymmdd echo date_i18n( 'l, F j, Y', strtotime( $release_date ) );?>

https://codex.wordpress.org/Function_Reference/date_i18n

FRONTEND - CONDITIONAL LOGIC<?php if ( get_field( 'has_video' ) ) : ?> <h3>Trailer</h3> <?php the_field('trailer'); //oEmbed ?> <hr><?php endif; ?>

http://www.advancedcustomfields.com/resources/code-examples/#using-conditional statements

FRONTEND - RELATIONAL PARENT (MOVIE)<ul> <?php $cast = get_field('cast'); foreach( $cast as $post): // var must be called $post (IMPORTANT) setup_postdata( $post ); ?> <li> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> <?php the_post_thumbnail(); ?> </a> </li>

<?php wp_reset_postdata(); // IMPORTANT - reset the $post object // so the rest of the page works correctly endforeach; ?></ul>

http://www.advancedcustomfields.com/resources/code-examples/#using-conditional statements

FRONTEND - RELATIONAL CHILD (ACTOR)get_posts()

<?php $movies = get_posts( array( 'post_type' => 'movie', 'meta_query' => array( array( 'key' => 'cast', // Field Name (ACF) 'value' => '"' . get_the_ID() . '"', //Leave "" 'compare' => 'LIKE' ) ) ));?>

http://www.advancedcustomfields.com/resources/tutorials/querying-relationship-fields/

FRONTEND - RELATIONAL CHILD (ACTOR)Show parents related

<ul> <?php $movies = get_posts(...); //See Previous Slide foreach( $movies as $post): // var must be called $post (IMPORTANT) setup_postdata( $post ); ?> <li> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> <?php the_post_thumbnail(); ?> </a> </li>

<?php wp_reset_postdata(); // IMPORTANT - reset the $post object // so the rest of the page works correctly endforeach; ?></ul>

http://www.advancedcustomfields.com/resources/tutorials/querying-relationship-fields/

WHY ACF?

Doesn't create MySQL table

User Interface900,000+

WP Way

DocumentationSupport

similar Plugins at http://comparewp.org/

ACF PRO - EXTRASLocal JSONFields in Comments, Widget, UsersValidation PHP + AJAXacf_form()

BEYOND THIS TALKWordPress Plugins: Advanced Custom FieldsJared Novack: Advanced Advanced Custom FieldsUsing Advanced Custom Fields within a WordPress Custom Theme

Elliot Condon talks - WP Melbourne:

Story of Advanced Custom Field - May 2013ACF 5 Walk-through - May 2014

QUESTIONS?

CHEERS MATE!

By / Leo Caseiro @leocaseiro