Yes, I can confirm that ACF is having a hard time loading formatted values in a multi-site field when running during the context of a acf/load_field/name=
.
1. Request starts at main site
2. I have a filter such as: add_filter('acf/load_field/name=schools', function($field) {});
3. Inside the closure of this filter, I run switch_to_blog(3)
and then get_field('state', 'options');
Where state
is a field of type “Select” such as:
ny : New York
fl : Florida
And is configured to return Both (Array)
. But due to a probable issue with ACF, likely at the values
data store, it returns the unformatted value ny
only.
What I had to do was a dirty workaround:
// Pre-load the school state value in the "plugins_loaded" context
add_action('plugins_loaded', function() {
if (!is_not_editing_schools()) {
return;
}
switch_to_blog(3);
global $school_state;
$school_state = get_field('state', 'options'); // ['ny' => 'New York'], as expected
});
add_filter('acf/load_field/name=schools', function($field) {
global $school_state;
// Now I have ['ny' => 'New York'] here, while in this context I was only able to get 'ny' out of get_field after switch_to_blog.
});
Hi John,
many thanks. This works fine.
But how can I add a “read more” Link after each answer?
Example: <p>Read more about <strong><a href="<?php the_permalink(); ?>"><?= the_title(); ?></a></strong></p>
I would try using htmlspecialchars().
On the other hand if I was doing this I would probably built and array in PHP and then json_encode that array for output allowing PHP to deal with special characters.
<?php
if ($faq) {
$ld = array(
'@context' => 'https://schema.org',
'@type' => 'FAQPage',
'mainEntity' => array()
);
if (have_rows('faq')) {
while (have_rows('faq')) {
the_row();
$ld['mainEntity'][] = array(
'@type' => 'Question',
'name' => get_sub_field('question'),
'acceptedAnswer' => array(
'@type' => 'Answer',
'text' => get_sub_field('answer')
)
);
}
}
?>
<script type="application/ld+json"><?php echo json_encode($ld); ?></script>
<?php
}
?>
What you are experiencing is the WP remembers where meta boxes are positioned and it is not a function of ACF. When any user moves a metabox WP remembers where is was moved to and displays in that location until they move it again. WP stores this information in the DB in the _usermeta table for each user. The meta_key of these entries is "meta-box-order_{$screen}"
. This will even override the position you set for a field group if you change it after the value is added to the DB. The only way to reset this is to do into the DB and delete these entries.
There is a plugin but it only works for the currently logged in user and I do not know if it works for CPTs or on Taxonoies. https://wordpress.org/plugins/reset-meta-box-positions/
The code above has the wrong post_type
It’s also taken from the example, like I sent you earlier but I’d adjusted it to your custom post.
Do you have any plugins blocking emails?
I know the code used works as it’s the same as I use on my sites.
What if you switch to a default theme and add the code, does it work?
Can you hardcode the values in this line:
$headers = 'From: ' . $name . ' <' . $email . '>' . "\r\n";
I have a feeling you can’t access custom fields at this stage, I think you have to access the info via the field key
many thanks for the help
yes my current form works since the recipes arrive in the recipe post type
but it still does not work with your model
So I tried this model but it doesn’t work either
I am staying with hostinger
in the function.php file
add_action('acf/save_post', 'my_save_post');
function my_save_post( $post_id ) {
// bail early if not a contact_form post
if( get_post_type($post_id) !== 'contact_form' ) {
return;
}
// bail early if editing in admin
if( is_admin() ) {
return;
}
// vars
$post = get_post( $post_id );
// get custom fields (field group exists for content_form)
$name = get_field('name', $post_id);
$email = get_field('email', $post_id);
// email data
$to = '[email protected]';
$headers = 'From: ' . $name . ' <' . $email . '>' . "\r\n";
$subject = $post->post_title;
$body = $post->post_content;
// send email
wp_mail($to, $subject, $body, $headers );
}
and in a contact page
<?php /*Template Name: pagecontactt*/;
acf_form_head();
get_header();
?>
<div id="content">
<?php
acf_form(array(
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
'new_post' => array(
'post_type' => 'contact_form',
'post_status' => 'publish'
),
'return' => home_url('merci'),
'submit_value' => 'Send'
));
?>
</div>
<?php get_footer(); ?>
thanks for the help
Does your WP site send emails ok? yes
Is the form on a custom post page for the recipe? Yes
here is the form code
<?php /*Template Name: User Submit*/;?>
<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id="container" >
<div class="row">
<div class="col-sm-12">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<!-- a supprimer si on enlève l'éditeur par défaut -->
<?php the_content(); ?>
<!------------>
<p> <?php the_field('Ingredients'); ?></p>
<p> <?php the_field('Preparation'); ?></p>
<p> <?php the_field('Cuisson'); ?></p>
<p> <?php the_field('Temps'); ?></p>
<p> <?php the_field('Difficulté'); ?></p>
<!-- <p> <?php the_field('image'); ?></p>-->
<p> <?php the_field('gallery'); ?></p>
<?php $options = array('post_id' => 'new',
'field_groups' => array(4),
'post_title' => false,
'post_type' => 'recette',
'post_status' => 'draft',
//'updated_message' => 'Merci pour votre participation!Votre recette sera publiée prochainement',
'return' => home_url('merci'),
//'submit_value' => 'Postez votre recette'
'submit_value' => 'Send'
);
acf_form($options);?>
<?php endwhile; ?>
</div>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
thank you for the correction but unfortunately I do not receive any mail, nor in spam
// Sending email after Front-end post submission
add_action('acf/save_post', 'yourdomain_save_post', 15);
function yourdomain_save_post($post_id) {
// Return if not a post
if( get_post_type($post_id) !== 'recette' ) { // here 'post' will be your post type
return;
}
// Return if editing in admin
if( is_admin() ) {
return;
}
// Vars
$post = get_post( $post_id );
$title = wp_strip_all_tags(get_the_title($post->ID));
$to = "[email protected]";
$subject = "Form submission successful";
$message = "Your message here";
$headers = array(
'Content-Type: text/html; charset=UTF-8',
#'Bcc:' . '[email protected]',
'From: '.get_option( 'blogname' ).' <[email protected]>'
);
// send email
wp_mail($to, $subject, $body, $headers );
}
Your WP site definitely sends emails?
Your code (which goes in the functions.php file) is still wrong. Try:
$to = "[email protected]";
$subject = "Form submission successful";
$message = "Your message here";
$headers = array(
'Content-Type: text/html; charset=UTF-8',
#'Bcc:' . '[email protected]',
'From: '.get_option( 'blogname' ).' <[email protected]>'
);
// send email
wp_mail($to, $subject, $body, $headers );
Ensure you change the [email protected] in the FROM field to a valid email account on your server
thanks for your help, i just changed the code again, but i still don’t receive email, nothing in spam either. maybe I indicate in the wrong places my email to receive emails
// Sending email after Front-end post submission
add_action('acf/save_post', 'yourdomain_save_post', 15);
function yourdomain_save_post($post_id) {
// Return if not a post
if( get_post_type($post_id) !== 'recette' ) { // here 'post' will be your post type
return;
}
// Return if editing in admin
if( is_admin() ) {
return;
}
// Vars
$post = get_post( $post_id );
$title = wp_strip_all_tags(get_the_title($post->ID));
$to = "{'[email protected]'}";
$subject = "{$blog_title} :: {$title}";
$message = "Your message here";
$headers = array(
'Content-Type: text/html; charset=UTF-8',
#'Bcc:' . '[email protected]',
'From: '.get_option( 'blogname' ).' <[email protected]>'
);
// send email
wp_mail($to, $subject, $body, $headers );
}
Hi @jarvis,
It worked, but not 100% but looking better thanks 🙂
This is the code which I updated slightly;
$args = array(
'post_type' => 'cars',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
'post_type' => 'cars',
'post_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'sold',
'value' => array('no'),
'compare' => 'IN',
),
)
)
);
$wp_query = new WP_Query($args);
if ($wp_query->have_posts()) :
$get_price = array();
while ($wp_query->have_posts()) : $wp_query->the_post();
$get_price[] = get_field('price');
endwhile;
endif; #endif $wp_query
$filter_price = array_unique($get_price);
if($filter_price):
echo '<select name="sort_price" id="sort_price">';
echo '<option value="" selected disabled>Select...</option>';
echo '<option value="">All</option>';
foreach($filter_price as $price):
$args = array(
'post_type' => 'cars',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'price',
'value' => $price,
'compare' => '<='
),
array(
'key' => 'sold',
'value' => array('no'),
'compare' => 'IN',
)
)
);
$wp_query = new WP_Query($args);
$figure_total = $wp_query->found_posts;
$count = count( $wp_query->get_posts() );
$round_price = round($price, -3);;
echo '<option value="'.$round_price.'">Up to £'.$round_price.' ('.$count.')</option>';
wp_reset_query();
endforeach;
echo '</select>';
endif; #endif $filter_price
It outputs the fields but seems to have duplicated them – so the options are;
<option value="5000">Up to £5000 (4)</option>
<option value="7000">Up to £7000 (6)</option>
<option value="7000">Up to £7000 (8)</option>
<option value="8000">Up to £8000 (9)</option>
<option value="10000">Up to £10000 (12)</option>
<option value="10000">Up to £10000 (1)</option>
<option value="9000">Up to £9000 (11)</option>
<option value="6000">Up to £6000 (5)</option>
<option value="8000">Up to £8000 (10)</option>
<option value="7000">Up to £7000 (7)</option>
<option value="4000">Up to £4000 (2)</option>
<option value="5000">Up to £5000 (3)</option>
As you can see it duplicates them and some of the counts aren’t right as
Upto £40000 (0) [cars in that price range]
Upto £50000 (2) [cars in that price range]
Upto £50000 (3) [cars in that price range]
Hello
thanks for the code, but I still do not receive an email, here is my new code
// Sending email after Front-end post submission
add_action('acf/save_post', 'yourdomain_save_post', 15);
function yourdomain_save_post($post_id) {
// Return if not a post
if( get_post_type($post_id) !== 'recette' ) { // here 'post' will be your post type
return;
}
// Return if editing in admin
if( is_admin() ) {
return;
}
// Vars
$post = get_post( $post_id );
$title = wp_strip_all_tags(get_the_title($post->ID));
$to = "{$admin_email}";
$subject = "{$blog_title} :: {$title}";
$message = "Your message here";
$headers = array(
'Content-Type: text/html; charset=UTF-8',
#'Bcc:' . '[email protected]',
'From: '.get_option( 'blogname' ).' <[email protected]>'
);
// send email
wp_mail($to, $subject, $body, $headers );
}
I think I misunderstood what you were asking before, hope this is what your looking for.
ACF output:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 150"><path style="fill:#fff" d="M3.305 49.574v79.388h143.916V49.708L75.382 80.745 3.305 49.574z"></path><path style="fill:#fff" d="M3.305 21.777v13.846l72.077 31.172 71.839-31.068v-13.95H3.305z"></path></svg>
Hardcoded output:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 150"><path style="fill:#fff" d="M3.305 49.574v79.388h143.916V49.708L75.382 80.745 3.305 49.574z"></path><path style="fill:#fff" d="M3.305 21.777v13.846l72.077 31.172 71.839-31.068v-13.95H3.305z"></path></svg>
Look identical to me.
Below is a screenshot of the actual output. The top <svg>
tag is the acf field and the bottom is the hardcode between the <a>
tag. Disregard the <img>
tag as I’m using the SVG plugin till this is resolved.
Here’s the code:
$social_icon_static = get_field('social_icon_static', $item);
//$social_icon_hover = get_field('social_icon_hover', $item);
if ( $depth == 0 ) {
$item_output .= '</span><div class="uk-inline-clip uk-transition-toggle uk-animation-toggle social-icon-container" tabindex="0">
<img class="uk-animation-slide-top uk-animation-reverse social-top" width="16px" height="16px" src="">
'. get_template_part( 'assets/images/svg/inline', $social_icon_static) .'
<img class="uk-transition-slide-bottom social-bottom" width="16px" height="16px" src="">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 150"><path style="fill:#fff" d="M3.305 49.574v79.388h143.916V49.708L75.382 80.745 3.305 49.574z"/><path style="fill:#fff" d="M3.305 21.777v13.846l72.077 31.172 71.839-31.068v-13.95H3.305z"/></svg>
</div>';
}
Sorry, I think misunderstood what you were asking before.
Here’s what the ACF field outputs:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 150"><path style="fill:#fff" d="M3.305 49.574v79.388h143.916V49.708L75.382 80.745 3.305 49.574z"></path><path style="fill:#fff" d="M3.305 21.777v13.846l72.077 31.172 71.839-31.068v-13.95H3.305z"></path></svg>
Here’s the hardcode:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 150"><path style="fill:#fff" d="M3.305 49.574v79.388h143.916V49.708L75.382 80.745 3.305 49.574z"></path><path style="fill:#fff" d="M3.305 21.777v13.846l72.077 31.172 71.839-31.068v-13.95H3.305z"></path></svg>
Look identical to me.
Here’s a screenshot of the output. The top <svg>
tag is the acf field rendering outside the <a>
tag and the bottom is the hardcoded version. Disregard the <img>
tag, I decided to use the SVG plugin till we resolve this.
Hope this is what you were asking for.
What about something like:
<?php
if($filter_price):
echo '<select name="sort_price" id="sort_price">';
echo '<option value="" selected disabled>Select...</option>';
echo '<option value="">All</option>';
foreach($filter_price as $price):
echo '<p>Price: '.$price.'</p>';
$args = array(
'post_type' => 'cars',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'price',
'value' => $price,
'compare' => '<='
),
)
);
$wp_query = new WP_Query($args);
$figure_total = $wp_query->found_posts;
$count = count( $wp_query->get_posts() );
#echo '<p>$figure_total: '.$figure_total.' count: '.$count.'</p>';
$round_price = round($price, -3);;
echo '<option value="'.$round_price.'">Up to £'.$round_price.' ('.$count.')</option>';
wp_reset_query();
endforeach;
echo '</select>';
endif; #endif $filter_price
Again, untested code so may error or need some tweaking!
Hi @jarvis,
Thanks, that’s amazing!
Just wondering now in the foreach loop how I add my select fields – for example;
<select name="sort_price" id="sort_price">
<option value="" selected disabled>Select...</option>
<option value="">All</option>
<option value="5000">Up to £5000 (<?php echo $count; ?>)</option>
<option value="6000">Up to £6000 (<?php echo $count; ?>)</option>
<option value="7000">Up to £7000 (<?php echo $count; ?>)</option>
<option value="8000">Up to £8000 (<?php echo $count; ?>)</option>
<option value="9000">Up to £9000 (<?php echo $count; ?>)</option>
<option value="10000">Up to £10,000 (<?php echo $count; ?>)</option>
</select>
hi jarvis,
i’ve just spun up a fresh install, in Italian as Site Language before i did anything else, then imported pages, repeaters, CPT, and ACF fields and groups.
I think i’m a bt closer to understanding what’s causing the issue, but not why or how to fix it. i use Oxygen, and it’s Repeater function to show my CPT (events) and it’s ACF fields (artist name, event venue, event date, address etc) on the page.
i build the repeater array like this:
post type: event
meta_query > array: key: ‘single_event_date’ (ACF field), value: PHP Function return Value – ‘event_order’, compare: < (past dates)
‘event_order’ is a custom function written like this:
function event_order() {
$today = date(‘Ymd’);
return $today;
}
the objective is this: there’s a bunch of events set in the past and future. in some arrays i want to show only Future events, in others i want to show only past events. the array key is an ACF field called ‘single_event_date.’ the PHP value is today’s date (expressed as the new function ‘event_order’), and the array compares today’s date to the single_event_date to separate those events that are in the past, and those that are in the future.
the problem is this: when the Site Language is English, the code snippet and the meta_query arrays work perfectly. in the old site, switching Site Language to Italian broke everything. and in thhis new test intall the same thing happens. WHY, and why when the site language isn’t English, i have no idea, but it’s the snippet, and ACF. any ideas?
Photo Gallery looks like a plugin add-on as seen here.
So try adding the code from the plugin example to your template:
<?php
//Get the images ids from the post_metadata
$images = acf_photo_gallery('gallery', $post->ID);
//Check if return array has anything in it
if( count($images) ):
//Cool, we got some data so now let's loop over it
foreach($images as $image):
$id = $image['id']; // The attachment id of the media
$title = $image['title']; //The title
$caption= $image['caption']; //The caption
$full_image_url= $image['full_image_url']; //Full size image url
$full_image_url = acf_photo_gallery_resize_image($full_image_url, 262, 160); //Resized size to 262px width by 160px height image url
$thumbnail_image_url= $image['thumbnail_image_url']; //Get the thumbnail size image url 150px by 150px
$url= $image['url']; //Goto any link when clicked
$target= $image['target']; //Open normal or new tab
$alt = get_field('photo_gallery_alt', $id); //Get the alt which is a extra field (See below how to add extra fields)
$class = get_field('photo_gallery_class', $id); //Get the class which is a extra field (See below how to add extra fields)
?>
<div class="col-xs-6 col-md-3">
<div class="thumbnail">
<?php if( !empty($url) ){ ?><a href="<?php echo $url; ?>" <?php echo ($target == 'true' )? 'target="_blank"': ''; ?>><?php } ?>
<img src="<?php echo $full_image_url; ?>" alt="<?php echo $title; ?>" title="<?php echo $title; ?>">
<?php if( !empty($url) ){ ?></a><?php } ?>
</div>
</div>
<?php endforeach; endif; ?>
Hi jarvis
thank you very much for your help
It’s super nice
But I just realized that I already have a problem when I use my form
When I click on add images nothing happens
The add button turns black
Here are screenshots
These are of course tests that I carry out
<?php /*Template Name: User Submit*/;?>
<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id="container" >
<div class="row">
<div class="col-sm-12">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<!-- a supprimer si on enlève l'éditeur par défaut -->
<!------------>
<p> <?php the_field('Ingredients'); ?></p>
<p> <?php the_field('Cuisson'); ?></p>
<p> <?php the_field('Temps'); ?></p>
<p> <?php the_field('Preparation'); ?></p>
<p> <?php the_field('Difficulté'); ?></p>
<p> <?php the_field('gallery'); ?></p>
<?php $options = array('post_id' => 'new',
'field_groups' => array(4),
'post_title' => true,
'post_type' => 'recette',
'post_status' => 'draft',
//'updated_message' => 'Merci pour votre participation!Votre recette sera publiée prochainement',
'updated_message' => __("Recette publiée", 'acf'),
//'return' => home_url('merci'),
'%post_url%', // Redirect to new post url
'submit_value' => 'Postez votre recette'
//'submit_value' => 'Send'
);
acf_form($options);?>
<?php endwhile; ?>
</div>
</div><!-- #content -->
</div><!-- #primary -->
<?php //get_footer(); ?>
Hi @flexi2202
This is what I use and it works ok:
$post = get_post( $post_id );
$title = wp_strip_all_tags(get_the_title($post->ID));
$to = "{$admin_email}";
$subject = "{$blog_title} :: {$title}";
$message = "Your message here";
$headers = array(
'Content-Type: text/html; charset=UTF-8',
#'Bcc:' . '[email protected]',
'From: '.get_option( 'blogname' ).' <[email protected]>'
);
// send email
wp_mail($to, $subject, $body, $headers );
Perhaps alter for your own needs and see if it works.
I think you’re missing a parameter.
The example in the docs shows:
[acf field="field_name" post_id="123"]
As you’re using a tax/cat, you would need to pass in the ID I think.
So something more like:
[acf field="field_name" post_id="term_X"] # X is the term ID you're getting the value from
There were 2 errors in the code:
1) The second loop had post_type twice
2) The wp_reset_query was in the wrong place
$args = array(
'post_type' => 'cars',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
'post_type' => 'cars',
'post_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'sold',
'value' => array('no'),
'compare' => 'IN',
),
)
)
);
$wp_query = new WP_Query($args);
if ($wp_query->have_posts()) :
$get_price = array();
while ($wp_query->have_posts()) : $wp_query->the_post();
$get_price[] = get_field('price');
endwhile;
endif; #endif $wp_query
echo '<pre>';
print_r($get_price);
echo '</pre>';
$filter_price = array_unique($get_price);
echo '<pre>';
print_r($filter_price);
echo '</pre>';
if($filter_price):
foreach($filter_price as $price):
echo '<p>Price: '.$price.'</p>';
$args = array(
'post_type' => 'cars',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'price',
'value' => $price,
'compare' => '<='
),
)
);
$wp_query = new WP_Query($args);
$figure_total = $wp_query->found_posts;
$count = count( $wp_query->get_posts() );
echo '<p>$figure_total: '.$figure_total.' count: '.$count.'</p>';
wp_reset_query();
endforeach;
endif; #endif $filter_price
I’ve tried the above code and it worked for me!
Hi @jarvis,
No problem, here is the full code;
$args = array(
'post_type' => 'cars',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
'post_type' => 'cars',
'post_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'sold',
'value' => array('no'),
'compare' => 'IN',
),
)
)
);
$wp_query = new WP_Query($args);
if ($wp_query->have_posts()) :
$get_price = array();
while ($wp_query->have_posts()) : $wp_query->the_post();
$get_price[] = get_field('price');
endwhile;
endif; #endif $wp_query
echo '<pre>';
print_r($get_price);
echo '</pre>';
$filter_price = array_unique($get_price);
echo '<pre>';
print_r($filter_price);
echo '</pre>';
if($filter_price):
foreach($filter_price as $price):
echo '<p>Price: '.$price.'</p>';
$args = array(
'post_type' => 'cars',
'posts_per_page' => -1,
'post_type' => 'your post type',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'price',
'value' => $price,
'compare' => '<='
),
)
);
$wp_query = new WP_Query($args);
$figure_total = $wp_query->found_posts;
$count = count( $wp_query->get_posts() );
echo '<p>$figure_total: '.$figure_total.' count: '.$count.'</p>';
endforeach;
endif; #endif $filter_price
wp_reset_query();
Thanks again for the help in cracking this!
John, thanks for the add_attachment
tip.
I also found similar code at https://wordpress.stackexchange.com/a/310689/39300
Whilst it assumes Post is the connected object, it also works for User.
The following code now takes the connected User’s name and uses that also for Title and Alt fields.
All told, now I have:
Thanks!
/**
* ==============================================================================
* ALSO SET IMAGE TITLE & ALT TO USER/POST NAME
* When an image is uploaded, use the attached Post (User) edtails
* to set Title, Alt fields etc.
* cf. https://wordpress.stackexchange.com/a/310689/39300
* cf. https://support.advancedcustomfields.com/forums/topic/force-an-image-file-upload-to-a-particular-directory/page/2/
* ==============================================================================
*/
// https://wordpress.stackexchange.com/a/310689/39300
function my_set_image_meta_upon_image_upload( $post_ID ) {
// "the first thing that your action should do is to remove
// itself so that it does not run again."
remove_filter('add_attachment', 'your_function_name_here');
// Check if uploaded file is an image, else do nothing
if ( wp_attachment_is_image( $post_ID ) ) {
$my_image_title = get_post( $post_ID )->post_title;
// Added by Robert Andrews
// Get user name to use in image details
$user = get_user_by( 'slug', $my_image_title );
$user_name = $user->display_name;
$my_image_title = $user_name;
// Sanitize the title: remove hyphens, underscores & extra spaces:
// $my_image_title = preg_replace( '%[-_]+%', ' ', $my_image_title );
// Sanitize the title: capitalize first letter of every word (other letters lower case):
// $my_image_title = ucwords( strtolower( $my_image_title ) );
// Create an array with the image meta (Title, Caption, Description) to be updated
// Note: comment out the Excerpt/Caption or Content/Description lines if not needed
$my_image_meta = array(
'ID' => $post_ID, // Specify the image (ID) to be updated
'post_title' => $my_image_title, // Set image Title to sanitized title
// 'post_excerpt' => $my_image_title, // Set image Caption (Excerpt) to sanitized title
// 'post_content' => $my_image_title, // Set image Description (Content) to sanitized title
);
// Set the image Alt-Text
update_post_meta( $post_ID, '_wp_attachment_image_alt', 'Photo of '.$my_image_title );
// Set the image meta (e.g. Title, Excerpt, Content)
wp_update_post( $my_image_meta );
}
}
Hi @pbalazs89
You could run 2 queries.
The first loop you would query by the custom field ‘featured’ and set the posts per page to 2
You then add another loop but this time query by the next custom field.
Would that work for you?
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.