ACF: Querying relationship fields with Author

The users doesn’t have permalinks nor titles. They have author links and display names. Changed the code: <?php while ( have_posts() ) : the_post(); ?> <h2>Resturants</h2> <?php $resturants = get_users(array( // Changed from get_posts ‘fields’ => ‘all_with_meta’, // All with meta to get also display_name ‘meta_query’ => array( array( ‘key’ => ‘resturant’, // name of … Read more

ACF repeater field usage

Simply use get_sub_field(“session_speaker”); function to retrieve that data. As you’ve said this is a relational field, it will return an array of post objects according to the docs. In order to get data from each speaker, you need to loop through the resulting array. Example: $speakers = get_sub_field(“session_speaker”); if ($speakers && count($speakers)>0) { foreach ($speakers … Read more

Dynamically Insert Image Into Stylesheet

Typically with themes that support custom styles/images, you define everything you can in your stylesheet, and then add the dynamic styles inline: .header { background-position: 50% 50%; background-repeat: no-repeat: background-size: whatever; } And in your templates: <div class=”header”<?php if ( $image ) printf( ‘ style=”background-image: url(%s);”‘, $image ) ?>> Title </div>

How to create an ACF shortcode with Repeater Field in WordPress? [duplicate]

you need to return your code when using shortcodes. Additionally you didn’t close the function. try this: function menu_loop() { $menu = ‘<div class=”entry-content dishes”>’; // check if the repeater field has rows of data if (have_rows(‘menu_sections’)): // loop through the rows of data while (have_rows(‘menu_sections’)) : the_row(); // display a sub field value $menu … Read more

Hide ACF from source code until a “show” button is clicked

You’re going to need to $.ajax() the contents of the field(s) on a click. In a nutshell: In your page template <?php global $post; $post_id = $post->ID; ?> <button class=”acf-get-content-button”>Let’s see that content</button> <div id=”acf-content-wrapper” data-id=”<?php echo $post_id; ?>”></div> JS (function($) { $(‘.acf-get-content-button’).click(function(e){ e.preventDefault(); var $contentWrapper = $( ‘#acf-content-wrapper’ ); var postId = $contentWrapper.data( ‘id’ … Read more

Sort a custom post with ACF: Date Picker & Display Featured!

Please change your args like this. $meta_query = array( array( ‘key’ => ‘event_type’, ‘value’ => ‘featured’, ‘compare’ => ‘=’ ) ); $args = array( ‘post_type’ => ‘event’, ‘posts_per_page’ => -1, ‘order’ => ‘DESC’, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘event_date’, ‘meta_query’ => $meta_query );