You need to add the custom properties on your template, e.g. header.php.
<style>
:root {
--color-1: <?php the_field( 'color_1' ); ?>
--color-2: <?php the_field( 'color_2' ); ?>
--color-3: <?php the_field( 'color_3' ); ?>
}
</style>
Because the 3 study paths are basically posts under the study_path post type, I imagine you can build a dropdown/radio selection and manually add the options by grabbing the 3 study path’s titles and post ids βorβ you can create a custom WP query to grab all posts under the study_path post type if you plan to add more posts down the road.
Do you need this to change on the backend or frontend? For the backend, you can change the prefix of a field using a filter. On the frontend, a regex to the field can determine whether to use mailto: or tel:.
I’m thinking storing the variables as an array in a PHP constant or WP transient (https://developer.wordpress.org/reference/functions/set_transient/).
Perhaps add this to your functions.php (from https://www.advancedcustomfields.com/resources/acf-format_value/)
add_filter('acf/format_value/name=this_meta_data', 'do_shortcode');
You can try to access the ACF plugin page directly by going to wp-admin/edit.php?post_type=acf-field-group
.
Add this to your single.php file where you want your button to appear:
if (get_field('show_external_link_button')) { ?>
<a class="post-button" href="<?php the_field('external_link_button_url') ?>"><?php the_field('external_link_button_label') ?></a><?php
}
Remember that this code needs to be inside a PHP code block. This will create a link with external_link_button_label
as the label and external_link_button_url
as the target.
To style the link as button add this snippet to your CSS file:
.post-button {
background-color: #4CAF50; /* Green background */
color: white; /* White text */
border: none; /* No border */
padding: 15px 32px; /* Padding */
text-align: center; /* Center the text */
text-decoration: none; /* No underline */
display: inline-block; /* Display on the same line */
font-size: 16px; /* Increase font size */
}
You can play around with the values to match your website’s styles.
One option is to retrieve the labels from one of your pages when you loop through them. Another option is to duplicate/recreate the ACF fields and store them elsewhere (like in an Options page) then grab that instead.
add_filter('acf/update_value/name=fotografia', 'acf_set_featured_image', 10, 3);
The fotografia
should be the name of your ACF image field and it should return the image ID.
You can create an ACF group and store it as the options for your selections, maybe use an Options page as a settings page. Using PHP you can dynamically generate the “left side” then for each loop grab the fields from that settings page to build the select box.
You can grab the post ID when you programmatically create it after your user completes their form then return the permalink with get_permalink($post_id)
.
You can try to add a filter that will select a default value if none is selected already. Perhaps something like this:
add_filter('acf/load_value/name=your_taxonomy_field_name', 'set_default_taxonomy_selection', 10, 3);
function set_default_taxonomy_selection($value, $post_id, $field) {
// Check if the field has a value
if (!$value && empty($_GET['post'])) {
// Set the default term ID here
$default_term_id = 7;
$value = $default_term_id;
}
return $value;
}
I know this is kinda late but perhaps could help others seeking to solve similar problems. I managed to do this by registering a transient value in the AJAX call which is immediately available to filter, populate, and correctly save post object selections.
You can’t return $maskapai
from the same variable. Try below. You may also need to adjust it depending on how you set up the field output.
<?php
// vars
$maskapai_list = get_field('maskapai');
// check
if( $maskapai_list ): ?>
<ul>
<?php foreach( $maskapai_list as $maskapai ): ?>
<li><?php echo $maskapai; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
I just realized the_title()
outputs the value. *facepalm* Try get_the_title()
instead. π
We really need to know how you structure your custom fields in the release CPT. I simply assumed in the release CPT you have a custom field named album_artist
which is a text field that holds the artist’s name. If so, then it was correct to match it with the title of the artist CPT which is also their name.
Release CPT
Post title: Death Magnetic
Album title (album_title
, text field): Death Magnetic
Album artist (album_artist
, text field): Metallica
Artist CPT
Post title (the_title()
): Metallica
So, meta_key => album_artist
= the_title()
.
Really, you just need to find what values you can match between your CPT and you’re all set.
Here’s a step-by-step.
1. Find a way to get the artist’s name. It’s stored as the post’s title. Great. We can grab it with the_title()
.
2. Find where the artist is declared in the ‘release’ CPT. It’s inside a custom field named album_artist
. Custom fields are stored inside meta keys.
3. Construct a query with these values and spit out the results. You get:
<?php
$args = array(
'numberposts'=> -1, // Fetch all posts...
'post_type'=> 'release', // from the 'release' CPT...
'meta_key' => 'album_artist', // which inside this meta key...
'meta_value' => the_title() // has this meta value.
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) :
echo '<ul>';
while ($my_query->have_posts()) : $my_query->the_post();
?>
<li><?php the_field('album_title') ?></li>
<?php
endwhile; echo '</ul>';
endif; wp_reset_query(); ?>
Hope that helped.
Assuming the artist’s name is the also the title for your “artist” post type, match it with the “artist_name” custom field in your “release” post type.
On your “artist” single post template:
// args
$args = array(
'numberposts'=> -1,
'post_type'=> 'release',
'meta_key' => 'artist_name',
'meta_value' => the_title()
);
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.