Post How to list taxonomy values in Advanced Custom Fields je prvi puta viđen na bbird.me.
]]>If you would like to list the values the user selects, you could try doing it with this code.
<?php $terms = get_field('custom_taxonomies'); if ($terms) { echo '<h1>Taxonomies:</h1> <p>'; $term_names = array(); foreach ($terms as $term) { $term_names[] = $term->name; } echo implode(' | ', $term_names),'</p>'; } ?>
Post How to list taxonomy values in Advanced Custom Fields je prvi puta viđen na bbird.me.
]]>Post Adding custom CSS class in body_class() using Advanced Custom Fields je prvi puta viđen na bbird.me.
]]>Having that said, assuming that CSS has already been prepared, all we need to do is to take the users’ choice and use it in the following way:
add_filter('body_class', 'add_acf_body_class'); function add_acf_body_class($class) { $field = get_field_object('custom_color', get_queried_object_id()); $value = get_field('custom_color'); $label = $field['choices'][$value]; $class[] = $label; return $class; }
You could add this into function.php or a custom plugin containing functions, whichever method you prefer. In order to get the current post ID, get_queried_object_id () is being used. We are also using get_field_object() to retrieve the color value.
Post Adding custom CSS class in body_class() using Advanced Custom Fields je prvi puta viđen na bbird.me.
]]>Post How to render shortcode using Advanced Custom Fields je prvi puta viđen na bbird.me.
]]>In order to render the shortcode, you could do something like this (this goes into template files):
<?php $revslider_shortcode = get_field( 'revolution_slider_shortcode' ); echo do_shortcode($revslider_shortcode); ?>
So the idea is to get the field value using get_field(), store it into variable and then render it using do_shortcode(). Also note the use of echo.
Post How to render shortcode using Advanced Custom Fields je prvi puta viđen na bbird.me.
]]>Post How to set conditional logic in Advanced Custom Fields je prvi puta viđen na bbird.me.
]]>
For this particular example, I used “Select” choice, creating select custom field type. Into Choices, let’s add few options:
The third step is to create few custom fields and attach the conditional logic on them. It isn’t important at this point what kind of fields do we have, as it could be anything. You could set one custom field to show the post URL, and the other one to show custom URL.
But how would you display custom fields depending on the choice being made? As you probably know, the_field() will display custom field value, but we can also find some use of get_field() here. This is how we could write the PHP function:
<?php if ( 'none' == get_field('custom_url_toggle')){ //do nothing } elseif ( 'first choice' == get_field('custom_url_toggle') ) { the_field("custom_url"); } elseif ( 'second choice' == get_field('custom_url_toggle') ) { the_field("regular_url"); } ?>
This function will display nothing if “none” is selected, it will display the content of custom_url field if “first choice”is selected and regular_url value if the “second choice”is selected.
Post How to set conditional logic in Advanced Custom Fields je prvi puta viđen na bbird.me.
]]>