Thanks John.
Thanks for the quick reply John
return value is value
The checkbox has multiple choices as follows
Natural
Denatured
Bacterial over expression
Insect cell over expression
Embryonic kidney extract
Other
However, no default values have been set.
I also used the example from your documentation under the Display Value sub heading and it returns another error
the_field('colors');
Notice: Array to string conversion
I assume this can be fixed by specifying both a value and label like this:
red : Red
However that will output the label for each when whats needed is comma delimited values only.
$values = get_field('your_field');
echo implode('; ', $values);
returns Warning: implode(): Invalid arguments passed
I used this withe the true/false Field Type :
$true = get_post_meta( get_the_ID(), 'true_false', true );
if ( $true == '1' ) {
// Do Something
}
Would also like to see this feature as you can currently target different menus in different menu locations so why not widget areas?
Example : If i create a shortcode function for use in different widget areas using a text or HTML widget and want to use values for each field which are different in each widget area.
Thanks John. Works perfectly.
I thought that might be built into ACF when selecting a location setting which adds the input field on all post/page types including archive archive and single but looks like i need to write the code to cover all types.
This is for the checkbox ( true/false ). I could also use something like this :
$checked = get_field( '_custom_field_key' );
All i want to do is add the checkbox to all edit screens for single posts/pages and all archive type pages to show the default widgets or when checked, the custom widgets.
Seems like get_field only works on single posts/pages and NOT on archive page types?
Yes, i worked that out so i had to use a different key for each. Thanks.
Here’s the code i used :
$logo_1 = get_post_meta( get_the_ID(), 'logo_1', true );
$logo_2 = get_post_meta( get_the_ID(), 'logo_2', true );
$logo_3 = get_post_meta( get_the_ID(), 'logo_3', true );
$logo_4 = get_post_meta( get_the_ID(), 'logo_4', true );
$logo_5 = get_post_meta( get_the_ID(), 'logo_5', true );
$key = [ $logo_1, $logo_2, $logo_3, $logo_4, $logo_5 ];
Hello John
Lets move away from sub & repeater fields.
How about using basic text or url fields with the same key.
With WP fields, i could use 1 custom field to add 5 different values
get_post_meta( get_the_ID(), 'logos', true );
And then this to get all the values
$key = get_post_custom_values( 'logos' );
How do i do this with ACF text or URL fields?
Resolved using this solution
There’s several ways to add ACF content to CPT archives depending on whether you want to include content from single CPT pages or you only want to display the ACF content on the archive page.
1. You can use code like this directly in your CPT archive template file
add_action( 'genesis_entry_content', 'function_name', 12 );
function function_name() {
$value = get_post_meta( get_the_ID(), 'key', true );
if ( ! empty( $value ) ) {
echo '<div class="your-class">'. $value .'</div>';
}
}
Or in your functions file with a conditional tag.
2. You can also use code to create a custom CPT archive template
There are other methods as well.
P.S Don’t forget to include a check for the ACF class
if ( ! class_exists( 'acf' ) )
return;
Here’s 2 different working code snippets which enable you to add custom field content to any Genesis loop using ACF or WordPress custom fields.
Create a template file in your child theme folder and use the WordPress Template Hierarchy to name the file and add the following code.
<?php
/**
* @author Brad Dalton
* @link https://wpsites.net/web-design/add-custom-field-to-genesis-loop/
*/
add_action( 'genesis_entry_content', 'function_name', 12 );
function function_name() {
$value = get_post_meta( get_the_ID(), 'key', true );
if ( ! empty( $value ) ) {
echo '<div class="your-class">'. $value .'</div>';
}
}
genesis();
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.