Created
July 5, 2017 23:30
-
-
Save iamcanadian1973/18d89e5813637c492ccc7e32ca514149 to your computer and use it in GitHub Desktop.
ACF- Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function _s_get_textarea( $text ) { | |
if( empty( $text ) ) { | |
return false; | |
} | |
return wpautop( $text ); | |
} | |
function _s_get_heading( $title, $wrap = 'h2', $attr = array() ) { | |
if( empty( $title ) ) { | |
return false; | |
} | |
// incase we want to return a raw string | |
if( $wrap == '' ) { | |
return $title; | |
} | |
$args = array( | |
'open' => "<{$wrap} %s>", | |
'close' => "</{$wrap}>", | |
'content' => $title, | |
'context' => ' ', | |
'attr' => $attr, | |
'params' => array( | |
'wrap' => $wrap, | |
), | |
'echo' => false, | |
); | |
$output = _s_markup( $args ); | |
return $output; | |
} | |
/* | |
Field name: hero_text | |
*/ | |
// Examples | |
// With simple fields there are 3 ways to capture a field value | |
the_field( 'hero_text' ); | |
echo $post->hero_text; | |
echo get_post_meta( get_the_ID(), 'hero_text', false ); | |
// Sometimes I'll have a helper function like above and use: | |
echo _s_get_heading( $post->hero_text, 'h3', array( 'class' => 'entry-title' ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment