IT WORKS, THANKS FOR LISTENING 😀
PS : I had 1st to query PLACE API
and then query geocode API with place_id to get some value as street_name, country, etc…
I think I have a start of solution.
I was using google maps Geocoding API, instead of place API.
with Place API I find all my hotels.
Need now to see If I can fill my ACF maps field with returned JSON..?
Got a message saying i’m spamming on contact or ticket…
thank you for your reply
Hi,
This is awesome !
Is it possible to do the same with custom taxonomy ?
because if I add page type with or without child / parent it doesn’t work as it is not a page but a taxonomy.
founded a solution here with getting original_id over here
but if someone have a better id !
i found Advanced Custom Field Multilingual in other forum topics,
but if i activate this plugin nothing changes, except that i can not query with 1104 as previously ^^
try with adding
$term = get_queried_object();
$aimage = get_sub_field('author_image',$term);
ok, got it !
$args = array(
'post_type' => 'maison-hotes',
'post__not_in' => $post_id,
'meta_query' => array(
'relation' => 'OR',
)
);
foreach($cities as $cities_id) {
$args['meta_query'][] = array(
'key' => 'contact_city', // name of custom field
'value' => '"'.$cities_id.'"', // matches exactly "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
);
}
if i do it manually, i get it to work
$args = array(
'post_type' => 'maison-hotes',
'post__not_in' => $post_id,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'contact_city', // name of custom field
'value' => '"1104"', // matches exactly "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
),
array(
'key' => 'contact_city', // name of custom field
'value' => '"1103"', // matches exactly "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
),
array(
'key' => 'contact_city', // name of custom field
'value' => '"1105"', // matches exactly "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
),
array(
'key' => 'contact_city', // name of custom field
'value' => '"1279"', // matches exactly "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
),
)
);
so i’m gonna do a foreach to get all my array, but i would like to understand whats wrong on the previous code
english is not my 1st language 😀 sorry 😛
indeed, thanks for taking time to look at this issue.
Hello, thanks for your reply !
your answear seems good but not totaly fix the issue (not tested), because i would be oblige to use it anytime i wish to display those links.
Just got an answear on Stackexchange, my problem was that i was defining global $post in my function.
if you want more explaination, here is the thread
https://wordpress.stackexchange.com/a/339859/139936
Also, i repeat, the get_the_title() works good.
with exactly the same settings. ( settings is relationship ID )
so this confirm the post data are good.
if i add this code before header, no whories at all. Its only when this hook take action on it.
Hello,
i already use setup_postdata()
my complete function :
global $wpdb,$post;
$results = $wpdb->get_results( "SELECT * FROM wp_posts, <code>wp_mec_dates</code> AS mecd, wp_icl_translations WHERE wp_posts.ID = mecd.post_id and post_status='publish' AND wp_icl_translations.language_code='$lang' AND dstart>'$startday' and wp_posts.ID = wp_icl_translations.element_id ORDER BY dstart LIMIT 0,5" );
if (count($results)> 0){
echo '<h3 class="widget-title"><span><i class="far fa-calendar-alt"></i> Les prochains événements</span></h3>';
foreach ($results as $post) {
setup_postdata($post);
$event_permalink = get_the_permalink();
$event_date = $post->dstart;
$new_event_date = date("d/m", strtotime($event_date));
$event_edate = $post->dend;
$new_event_edate = date("d/m", strtotime($event_edate));
$event_title = get_the_title();
$image_url = get_the_post_thumbnail_url('','liste-etablissements');
$event_cities = get_field('contact_city');
echo '<div class="events-sidebar"><div class="events-img">'."\n";
echo ' <a href="'. $event_permalink .'"><img src="'. $image_url .'" alt="" class="image"></a>'."\n";
echo ' </div>'."\n";
echo ' <div class="events-detail">'."\n";
echo ' <h3 class="presta-title"> <a title="" href="'.$event_permalink.'">'. substr($event_title,0,55) .'</a></h3>'."\n";
echo ' <div class="presta-decouvrir">'; if($new_event_edate != $new_event_date) { echo 'Du'; } else { echo 'Le'; } echo ' <b>' .$new_event_date; if($new_event_edate != $new_event_date) { echo '</b> au <b>'. $new_event_edate; } echo '</b><br />';
if($event_cities) { $cities = 0; $max_cities = 1; foreach($event_cities as $event_city) { $cities++; if($cities > $max_cities) { break; } echo 'Ã <a href="'. get_permalink( $event_city->ID ) .'" title="">'. get_the_title( $event_city->ID ) .'</a>'; } }
echo ' </div>'."\n";
echo ' </div></div><div style="clear:both;"></div>'."\n";
//echo $new_event_date . ' - <a href="'.$event_permalink.'" title="'.$event_title.'">' . substr($event_title,0,38) .'</a><br />';
}
}
wp_reset_postdata();
every data works, exept the relationship permalink.
if i deactivate my custom function in previous post, everything works well. But i don’t see in my function what is creating this trouble.
Hello,
after many investigation, i found what is making this trouble !
its a custom code i used to add a .html extension to all my pages & customs posts.
but i can not figure what in this code is creating this trouble :s
my function
function custom_post_permalink ($post_link) {
global $post;
if($post) {
$type = get_post_type($post->ID);
$post_type_data = get_post_type_object( $type );
$post_type_slug = $post_type_data->rewrite['slug'];
$post_type_slug_translated = apply_filters( 'wpml_get_translated_slug', $post_type_slug, $type);
$translated_home_url = apply_filters( 'wpml_home_url', home_url());
$be_current_lang = apply_filters( 'wpml_current_language', NULL );
if($be_current_lang=='fr'){
return $translated_home_url . $post_type_slug_translated . '/' . $post->post_name . '.html';
} else {
return $translated_home_url .'/'. $post_type_slug_translated . '/' . $post->post_name . '.html';
}
}
}
add_filter('post_type_link', 'custom_post_permalink');
Thanks in advance for your help
Hello,
Use relationship field type.
and then https://www.advancedcustomfields.com/resources/querying-relationship-fields/
Hello,
in the settings of your field, you have a “class” option.
you can define your class there, and then in CSS
p.yourclass { yourcss; }
If only 1 value in relation field :
$city_id = $bnb_ville[0]->ID;
if it could be more than 1 value :
$city_id = [];
foreach ($var as $post) {
$city_id[] = $post->ID;
}
$bnb_ville is the variable for get_field() !
See the code i added at the end of my previous reply.
Hello,
you should use :
order_by => ‘your_title_field’
order => ‘ASC’
works well on my side.
try adding a $term to your custom field & use get_field instead of the_field
$term = get_queried_object();
$property_adress = get_field('property_adress',$term);
echo $property_adress;
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.