1) I believe the compare word you are looking for is LIKE
.
2) meta_query
takes nested array, so your code should be like
$query = get_posts(array(
'post_type' => 'post',
'meta_query' => array(
array(
'key' => 'issue',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
));
https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
Cheers
In your functions.php code, you are checking if $icon
is truthy, but i think you mean $menu_navbar_sottotitolo
😉
Cheers
Is there a reason why you want to write it in the pure sql?
but if you wanna know how that WP_Query translate to the sql, you can print out the request.
$testimonials = new WP_Query( $args );
echo $testimonials->request; // <- this is the sql statement
Cheers
If i understand correctly, you are trying to get all the posts within “Contact Data” category and order those posts by the acf field “region_contacto”.
The way you run the query will not work, because the sorting will only happens inside each query.
If you want the posts to be sorted by the acf field, they should be within the same query, like so:
<?php
$news_cat_ID = get_cat_ID('Contact Data');
$news_query = new WP_Query( array(
'posts_per_page' => -1,
'cat' => $news_cat_ID,
'meta_key' => 'region_contacto',
'orderby' => 'meta_value',
'order' => 'ASC',
));
while ( $news_query->have_posts() ) : $news_query->the_post();
echo get_field('region_contacto') . '<br/>';
endwhile; wp_reset_query();
This should give you all the posts inside “Contact Data” category and ordered by the acf “region_contacto” value.
Cheers
one important question is, are the user entering their quite themselves or the site’s admin is going to do it.
If it’s the site admin, then i’d say it’s save to create three custom taxonomies for “publication name”, “related stories ID” and “publication author”.
If you just don’t like how the taxonomy meta box is on the sidebar. you can set the taxonomy “public” value to false when you registering, and use acf’s taxonomy field in stead.
So,
1) it’s be faster to query the quote under “publication name” instead of checking against the meta table
2) because they are taxonomy, you can check the existing ones or add new one on the fly.
Cheers
So, before you do your while loop. add another line right before it:
<?php var_dump($news_query->request); ?>
This should let you see what’s the actual sql query that gets executed. We can then debug further from there.
Here’s some directions for ya
1) the function get_the_term_list() returns the HTML https://codex.wordpress.org/Function_Reference/get_the_term_list. the function you are looking for is get_the_terms() https://developer.wordpress.org/reference/functions/get_the_terms/
2) when you initialize the WP_Query, take a look at what types of parameter you should pass to search in the category https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters. ‘category__in’ requires an array of term ids. And ‘cat’ requires a term id.
3) use get_the_content() to retrieve the post content https://developer.wordpress.org/reference/functions/get_the_content/
4) to update repeater field, you can either use update_field or update_sub_field functions.
https://www.advancedcustomfields.com/resources/update_field/
https://www.advancedcustomfields.com/resources/update_sub_field/
these should get you going with what you are trying to do.
Cheers!
the documentation can be found here: https://www.advancedcustomfields.com/resources/register-fields-via-php/. it tells you what are the minimal argument you need to pass to register a field group.
Cheers!
do you have other plugin that tries to modify the wp query?
to debug further,
try printing out the $news_query->request just after you initialize the WP_Query for the actual MYSQL statement and see if the order is actually format properly.
add_shortcode’s callback accepts 2 parameters. The first one being the attributes and the second on is the body content. https://developer.wordpress.org/reference/functions/add_shortcode/
Then you can use php’s array_slice to to slice the array with a starting index and length. http://php.net/manual/en/function.array-slice.php
So, you callback will look something like this:
function allphotos_shortcode($attrs) {
$attrs = shortcode_atts([
'start' => 0,
'number' => null,
], $attrs);
if (! $images = get_field('fl_gallery')) {
return '';
}
if (! $images = array_slice($images , $attrs['start'], $attrs['number'])) {
return '';
}
$output .= '<ul id="kalpht">';
foreach ($images as $image) {
$output .= sprintf(
'<li><a class="x-img-link" href="%s" data-options="%s">%s</a></li>',
$image['url'],
"thumbnail:'{$image['sizes']['mini-me']}'",
wp_get_attachment_image($image['id'], 'mini-me')
);
}
$output .= '</ul>' . do_shortcode('[lightbox opacity="0.9" thumbnails="true"]');
return $output;
}
cheers
🙂 thanks for 5.6 though, loving this one so far
Hi hi,
Here’s a simple example of how a addon extends the core field looks like:
https://gist.github.com/gummiforweb/3293ec7a0f0708df40c2ae5df8252fa3
Here’s some things I notice so far with the sample field,
1) When create new field, the field “My Custom Field” do show up in the field type dropdown, but after 5.6, “My Custom Field” doesn’t show up in the dropdown anymore.
5.5.14: https://www.screencast.com/t/weRD4owkUY
5.6.0: https://www.screencast.com/t/7BETqEES3
2) When editing and exiting field in a post, it’s loading repeater’s render_field. (i think this might be true for all the field actions/filters)
5.5.14: https://www.screencast.com/t/lVliDpia
5.6.0: https://www.screencast.com/t/YqDTz23RQ
Right now, a quick fixes on the addon part is to add an empty initialize method like:
public function initialize() {}
🙂
Yep, it doesn’t happen on all the addon, but i saw a couple ppl asking on github so i thought I’d post it here. The new constructor will only affect addon that extends on the existing core field.
2 of my addon are extending repeater field. and couple other ones i use that extends image and gallery field all run into the same issue.
Basically, what happen is, say, you have a addon that extends repeater field, the class look something like this:
class my_custom_field extends acf_field_repeater
{
public function __construct()
{
$this->name = 'my_custom_field';
// ... ohter stuff
// not calling on the repeater but the core field
acf_field::__construct();
}
}
So, with the new constructor, a field registration’s order will happen like this:
1. my_custom_field::__construct()
2. acf_field::__construct()
3. acf_field_repeater::initialize() <—-
the 3rd one, because my_custom_field will not have method called ‘initialize’, so it will call the repeater’s initialize() and will cause unexpected error depends on the addon. Because repeater’s initialize() will overwrite the correct $default, $name etc… properties. So, my_custom_field->name is actually “repeater” instead of “my_custom_field”.
I’m not sure if this is consider a bug, cause it’s more like the addon author need to fix their code 🙂
There’s actually another cleaner quick fix, which is adding an empty body initialize() method on the my_custom_field class
Hello,
Not sure if you are still needing this, but I had exactly the same situation as yours. I had button that have crazy conditions with multiple fields and needed to be used on many different field groups.
So I’ve created acf-component-field plugin, that does exactly what you described. Component Field Group are reusable and nest-able, with no extra php functions or classes you’d need to initiate in your theme.
Demo can be found here: http://gummi.io/acf-component-field/
Please feel free to play around in the backend and see how it’s setup.
I hope this helps you and anyone else who’s looking for this type of functionality. 🙂
Suggest you to use the google map field for the address.
ACF will also return you the longitude and latitude along with the address. With the longitude and latitude, then you are able to work with google map. Because to add a pin(marker) on google map, it requires a longlat value.
take a look at the google map field documentation.
http://www.advancedcustomfields.com/resources/google-map/
you can achieve this with simple WP’s query.
One thing to keep in mind, acf’s value are saved in the “wp_postmeta” table. So, your code would be similar to these lines:
$args = array (
'post_type' => 'post', // your post type
'posts_per_page' => -1, // grab all the posts
'meta_key' => 'your_acf_image_field_name',
'meta_compare' => 'EXISTS' // make sure the post have this acf value
);
$query = new WP_Query($args);
while ($query->have_posts()): $query->the_post();
// because the image value is saved as attachment_id
echo wp_get_attachment_image( get_field('your_acf_image_field_name') );
endwhile;
wp_reset_query();
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.