<?php
$slider_off = get_field('slider_off', 'option');
?>
<?php if ($slider_off) { ?>
<div class="special-discounts col-xxxl-3 col-xl-4 col-lg-4">
<div class="swiper mySwiper">
<div class="swiper-wrapper">
<?php foreach ($slider_off as $list) {
$item = $list['slider_off_product'];
$pro_id = $item->ID;
$myproduct = new WC_Product($pro_id);
$product = wc_get_product($pro_id);
$account_game = $product->get_attribute('platform');
$product_type = $product->get_type();
$stock = $myproduct->get_stock_quantity();
$pro_old_price = $myproduct->get_regular_price();
$pro_new_price = $myproduct->get_sale_price();
$pro_title = $product->get_name();
$pro_image = get_the_post_thumbnail($pro_id, array(192, 192));
$pro_link = get_permalink($pro_id);
$product_logo_pic = get_field('product_logo_pic', $item);
$differenceInSeconds = 0;
if ($product_type == 'variable') {
$variations = $product->get_available_variations();
$variations_id = wp_list_pluck($variations, 'variation_id');
if (!empty(get_defualt_attr($product))) {
...
}
if ($product->is_type('variable')) {
...
}
// Array row output
} else {
...
}
?>
<!-- code -->
<?php } ?>
</div>
</div>
</div>
<?php } ?>
HI, I can make the slider_off true or false , but I can’t make a connection between the slider_off_product and the product post in woocommerce ! How should I act to display the product post in this code? In fact, what is the meaning of the $item = $list[‘slider_off_product’]; in the code? And how should it be implemented in acf plugin ?
sorry for my bad english.
I have an acf that takes the woocommerce products (which are not translatable, so there is only the italian version), this is the structure:
acf_add_local_field_group(array(
'key' => 'group_65017e7235881',
'title' => 'Home CPO',
'fields' => array(
array(
'key' => 'field_65017e798dde7',
'label' => 'Orologi in evidenza',
'name' => 'orologi_in_evidenza',
'type' => 'repeater',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'collapsed' => '',
'min' => 0,
'max' => 0,
'layout' => 'table',
'button_label' => '',
'sub_fields' => array(
array(
'key' => 'field_65017e8a8dde8',
'label' => 'Orologio',
'name' => 'orologio',
'type' => 'post_object',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'post_type' => array(
0 => 'product',
),
'taxonomy' => array(
0 => 'product_cat:rolex-cpo',
),
'allow_null' => 0,
'multiple' => 0,
'return_format' => 'object',
'ui' => 1,
),
),
),
),
'location' => array(
array(
array(
'param' => 'page_template',
'operator' => '==',
'value' => 'index-cpo.php',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
));
If I use the italian language, then the repeater will display all the products available. Otherwise, if I switch to english language the repeater doesn’t show anything.
This issue is kinda weird ’cause in the english version I can see all the products from the woocommerce dashboard but not from the repeater.
I’m trying to change the lang parameter that is sent from the ajax request of acf, so I did this:
function customize_acf_query($args, $field, $post_type)
{
$args['lang'] = 'it';
return $args;
}
add_filter('acf/fields/post_object/query', 'customize_acf_query', 10, 3);
but again, the acf doesn’t display any products. Could someone help me?
Thanks in advance!
Hello,
I have a group of ACF number fields on an Options page for basic automatic calculations. All field values (entered and calculated) are then output to pages/posts using ACF shortcodes. Everything works great…until I add an acf/format_value function to format all numbers with commas. My understanding is that ACF/format_value only runs on the front end of the website. However, once my function is enabled, my calculated fields on the Options page are incorrect. I have a feeling I am missing something very basic – any suggestions are greatly appreciated.
Below is an example of the code I am using.
add_action('acf/save_post', 'count_my_pets', 5);
function count_my_pets($post_id)
{
$post_id = "options";
// ACF Option page field values.
$dogs = get_field('my_dogs', 'options');
$cats = get_field('my_cats', 'options');
$birds = get_field('my_birds', 'options');
// Calculate total pets.
$pets_total = $dogs + $cats + $birds;
// Update ACF field for total_pets.
update_field('total_pets', $pets_total, $post_id);
}
add_filter('acf/format_value/type=number', 'format_numbers', 10, 3);
function format_numbers($value, $post_id, $field)
{
$value = number_format($value);
return $value;
}
I’m building an AJAX filtering system and am trying to include a filter that can take multiple IDs and then filter custom post type posts based on its relationship field. Is there any handy method of doing meta_query with an array of values for a relationship field which is saved as array? I’m trying to achieve something like this
‘meta_query’ => array(
array(
‘key’ => ‘relationship_field’,
‘value’ => serialize([1234, 4321]),
‘compare’ => ‘LIKE’,
)
)
Is anything like this doable or is doing multiple OR conditioned meta queries the only option? This probably gets pretty heavy very quickly, so is there best practice on how many you should use, meaning I could probably limit how many IDs can be passed to the filtering function?
It’s possible to filter out posts that don’t match inside the loop with array_intersect IF statement, but that wouldn’t be very good for pagination.
Hey guys
So here is my situation:
I have an ACF select field where I added the values from the beginning like this:
Free
Free Trial
Paid
Now I installed a few Filter plugins on my WP to allow people to filter the posts based on this. The issue is that these plugins want the ACF structure like this:
free : Free
free_trial : Free Trial
paid : Paid
If I do that I will have to edit all my 5200 posts and manually assign the new value.
Question:
Is there any way to do this automatically via code, plugin, db search and replace…idk..anything?
Thank you
Hi
i got prob to query users with custom field repeater
What i made :
i got a custom search form, who search in ajax with get_users and with complexe request on many user’s customs fields
all work fine, even filter taxonomy assigned to user like custom field
but it dont work for my repeater field..
the repeater key is : liste_des_langues & the item key : langue
if add this :
function wpza_replace_repeater_field( $where ) {
$where = str_replace( "meta_key = 'liste_des_langues_$", "meta_key LIKE 'liste_des_langues_%", $where );
return $where;
}
add_filter( 'posts_where', 'wpza_replace_repeater_field' );
and this is my request args for this field :
if($langues && $langues != 'all'){
$temp = array(
'key' => 'liste_des_langues_$_langue',
'value' => $langues,
'compare' => 'LIKE',
);
array_push($request['meta_query'] , $temp);
}
this is the basic request :
$request = array(
'role__in' => array( 'consultant' ),
'meta_query' => array(),
'tax_query' => array(),
);
if(count($_GET) > 1){
$request['meta_query']['relation'] = 'AND';
}
but it doesn’t work :/
and i dont understand where is my mistake, someone can help please ?
A very basic question that I can’t seem to find an answer to and really hope someone can advise. Sorry, it’s so simple – I can (just about) adapt php code but am not a coder.
When I want to display the value of a WYSIWYG field, should I use the simple
<?php the_field(‘field_name’); ?>
Or should I put it in conditional logic in case the field value is null:
<?php if( get_post_meta($post->ID, “field-name”, true) ): ?>
<?php echo get_post_meta($post->ID, “field-name”, $single = true);?>
<?php endif; ?>
I don’t want to do anything else with these particular fields, just display them.
I’m asking both with regards to page load speed (eg number of database queries) and also to try to prevent some of the 504 crashes my site has been having recently when I am editing pages. (The crashes began when my husband rebuilt our AWS server in order to upgrade php for the upcoming Woocommerce php change requirement; we found that changing from php 7.4 to 8.1 helped matters but has not fixed issues and so I am now looking at trying to revise/check all of my coding.)
Hi there, I’m trying to set a setup_postdata($post) inside another setup_postdata($post) and after closing the last wp_reset_postdata(), the first loop doesn’t work anymore, any hint? This is because inside the first loop I have to get some data from another relationship field.
<?php $negatives = get_field( "collections_single_work"); ?>
<?php if( $negatives ): ?>
<?php foreach( $negatives as $post ): ?>
<?php setup_postdata($post); ?>
here goes some coding
<?php $collectionsizes = get_field( "collection_edition_size"); ?>
<?php if( $collectionsizes ): ?>
<?php foreach( $collectionsizes as $post ): ?>
<?php setup_postdata($post); ?>
here goes some coding
<?php wp_reset_postdata(); endforeach; ?>
<?php endif; ?>
here goes some coding which is part of the first loop and is not reading the previous setup_postdata($post)
<?php wp_reset_postdata(); endforeach; ?>
<?php endif; ?>
I have a field group with different fields which are assigned to a custom post type via post object.
profile_image (Image)
profile_function (Repeater)
profile_mail (Mail)
profile_phone (Phone)
These fields are output as follows:
<?php
$management = get_field('staff');
if ($management):
foreach ($management as $employee):
setup_postdata($employee);
?>
<div class="section__column--lg-4">
<div class="profile">
<div class="profile__image">
<img src="<?php echo get_field('profile_image', $employee->ID); ?>">
</div>
<div class="profile__body">
<div class="profile__name">
<?php $profile_title = get_the_title($employee); ?>
<strong><?php echo $profile_title; ?></strong>
</div>
<?php if (have_rows('profile_function', $employee->ID)): ?>
<div class="profile__function">
<ul class="profile__list">
<?php while (have_rows('profile_function', $employee->ID)) : the_row(); ?>
<li class="profile__item">
<?php echo get_sub_field('profile_function_entry', $employee->ID); ?>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
<?php if (get_field('profile_mail')): ?>
<div class="profile__mail">
<a class="profile__link">
<?php echo get_field('profile_mail', $employee->ID); ?>
</a>
</div>
<?php endif; ?>
<?php if (get_field('profile_phone')): ?>
<div class="profile__phone">
<?php echo get_field('profile_phone', $employee->ID); ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
I have created a new field group with flexible content which should output these fields as Post object. The problem is that only profile_image and profile_name and profile_function are displayed. profile_mail and profile_phone are missing from the output. What am I doing wrong?
<?php if(have_rows('management_block')): ?>
<?php while( have_rows('management_block')): the_row(); ?>
<?php if(get_row_layout() == 'management_entry'): ?>
<?php
$management = get_sub_field('management_profile');
if ($management):
foreach ($management as $employee):
setup_postdata($employee);
?>
<div class="section__column--lg-4">
<div class="profile">
<div class="profile__image">
<img src="<?php echo get_field('profile_image', $employee->ID); ?>">
</div>
<div class="profile__body">
<div class="profile__name">
<?php $profile_title = get_the_title($employee); ?>
<strong><?php echo $profile_title; ?></strong>
</div>
<?php if (have_rows('profile_function', $employee->ID)): ?>
<div class="profile__function">
<ul class="profile__list">
<?php while (have_rows('profile_function', $employee->ID)) : the_row(); ?>
<li class="profile__item">
<?php echo get_sub_field('profile_function_entry', $employee->ID); ?>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
<?php if (get_field('profile_mail')): ?>
<div class="profile__mail">
<a href="mailto:<?php echo get_field('profile_mail'); ?>" class="profile__link">
<?php echo get_field('profile_mail', $employee->ID); ?>
</a>
</div>
<?php endif; ?>
<?php if (get_field('profile_phone')): ?>
<div class="profile__phone">
<?php echo get_field('profile_phone', $employee->ID); ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
Hello.
Simple question.
How can I effectively delete fields from the database, when I delete them on the admin? I have created a couple of fields I no longer need/use, but they are still there, in the databse. That is junk on my precious database. Please, tell me there is a friendly way to clean up deleted fields. We are about to enter 2024.
Hi everyone,
I made a page builder type thing using Flexible Content and a bunch of layouts within that flexible content.
I know need to add a component that is itself a wrapper for other components, asides from cloning the flexible content field into the layout, is there any other way to do this?
{{--
Template Name: Page Builder
--}}
@extends('layouts.app')
@section('content')
<section class="page-blocks">
{{--
Loop through the layouts and render the appropriate blade file.
Note that our layouts use underscores and our Blade files use hyphens.
E.g. layout news_block references news-block.blade.php.
--}}
@if (have_rows('page_blocks'))
@while (have_rows('page_blocks'))
@php
the_row();
$layout = str_replace('_', '-', get_row_layout());
@endphp
@include('layouts.page-builder.' . $layout)
@endwhile
@endif
{{-- @php
$fields = get_fields();
@endphp
<ul>
@foreach ($fields as $name => $value)
<li><b>{{ $name }}</b> - {{ var_dump($value) }}</li>
@endforeach
</ul> --}}
</section>
@endsection
Inside this loop I have a wrapper component that contains a clone of the parent
<section class="multi-block-wrapper">
{{--
Loop through the layouts and render the appropriate blade file.
Note that our layouts use underscores and our Blade files use hyphens.
E.g. layout news_block references news-block.blade.php.
--}}
@if (have_rows('inner_page_blocks'))
@while (have_rows('inner_page_blocks'))
@php
the_row();
$layout = str_replace('_', '-', get_row_layout());
@endphp
@include('layouts.page-builder.' . $layout)
@endwhile
@endif
</section>
I’ve inherited a multi-site where both parent and child theme are using acf-json folders. The child theme is using json files with the same filename and group id key as the parent.
Presumably the developer expected that the child file would get used instead of the parent file as other template files do. Apparently when this site was launched it did work. Now there are problems.
I’m not sure where to start to fix. I could remake this file but that would require me redoing all the data entry. They also don’t want the parent options to load in the child options.
Looking for some guidance or suggestions. Thanks.
Hi everobody,
A rookie around here
When Inserting my ACF type link in a Grid template of WPBakery the results on the website are just text, the generated HTML looks like this:
<div field_64f75f5789e38="" class="vc_gitem-acf field_64f75f5789e38">text, url, link, </div>
So I have created the following function to replace this generated HTML for a custom one:
function custom_format_acf($value, $post_id, $field) {
if ($field['name'] === 'download_webinars_button' && is_array($value)) {
$title = isset($value['title']) ? $value['title'] : '';
$url = isset($value['url']) ? $value['url'] : '';
$target = isset($value['target']) ? $value['target'] : '_self';
$output = '<div class="vc_btn3-container vc_btn3-inline sqz-custom-card">';
$output .= '<a class="vc_general vc_btn3 vc_btn3-size-md vc_btn3-shape-rounded vc_btn3-style-modern vc_btn3-color-grey" ';
$output .= 'href="' . esc_url($url) . '" title="' . esc_attr($title) . '" target="' . esc_attr($target) . '">';
$output .= esc_html($title);
$output .= '</a>';
$output .= '</div>';
$value = trim($output);
}
return $value;
}
add_filter('acf/format_value/type=link', 'custom_format_acf', 10, 3);
And it works correctly, but I find that the generated code looks like this:
<div field_64f75f5789e38="" class="vc_gitem-acf field_64f75f5789e38">
,
<div class="vc_btn3-container vc_btn3-inline"><a class="vc_general vc_btn3 vc_btn3-size-md vc_btn3-shape-rounded vc_btn3-style-modern vc_btn3-color-grey" href="#form" title="patata en" target="">patata en</a></div>
,
</div>
And although everything seems to work fine, I get 2 commas at the beginning and end of my html code that I can’t get rid of.
Any ideas?
I have a custom post type which contains a custom taxonomy. I would like to make it so that a user cannot save their post unless they have chosen a value for this custom taxonomy. I expect them to use the admin interface to create their post. Is this possible? Thanks.
I have a product reviews CPT through ACF and it works fine, except when there are no posts published to the CPT. Instead it will show the list of blog posts. I’d like it to show the “No posts found.” Here is the code:
<main id="post-type__<?php echo $type;?>">
<section class="archive-title">
<div class="container container__archive-title container--wide">
<h1 class="category-title fs--huge"><?php echo single_cat_title( '', false );?></h1>
</div>
</section>
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'cat' => $cat,
'post_type' => $type,
'post_status' => 'publish',
'paged' => $paged
);
$reviewscpt = new WP_Query( $args );
if( $reviewscpt->have_posts()) :
$reviewcount = 0;?>
<section class="collection collection__archive--reviews">
<div class="container container__archive--reviews">
<ul class="archive__loop archive__loop--reviews loop">
<?php while( $reviewscpt->have_posts() ): $reviewscpt->the_post(); $reviewcount++;?>
<li class="loop-article review-article-<?php echo $reviewcount;?>">
<div class="collection__col collection__col--left">
<h1 class="loop-article__title fs--med">
<a>"><?php the_title(); ?></a>
</h1>
<p class="loop-article__excerpt"><?php the_excerpt(); ?></p>
<div class="loop-review__cta">
<p class="link link--lined link--review loop-article__cta">
<a>">Read Review</a>
</p>
<p class="callout__link review__buy-link loop-article__cta">
<a>">
<?php echo get_field('review_product_link_text', $post->ID);?></a>
</p>
</div>
</div>
<div class="collection__col collection__col--right">
<a>">
<?php the_post_thumbnail(); ?>
</a>
</div>
</li>
<div class="review-archive__divider">
</div>
<?php endwhile; ?>
</ul>
</div>
</section>
<div class="loop__nav">
<?php
echo paginate_links( array(
'format' => 'page/%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $reviewscpt->max_num_pages,
'prev_text' => '«',
'next_text' => '»'
) );?>
</div>
<?php else: ?>
<p>It looks like that's the end of the blog posts!</p>
<?php endif; ?>
<?php do_action('core_' . $type . '_category_after_loop');?>
</main>
I have a loop on the output of “gallery-image-” fields. But it outputs empty field values. How can I solve this?
<div class="slider-for">
<?for ($i=1; $i <= 10; $i++) {
$image = get_field('gallery-image-'.$i);
if ($image)
$slider_nav_HTML = '<div class="slider-item"><img src="'.$image.'" width="60" height="60" /></div>';
?>
<div><img />" width="100%"></div>
<?}?>
Hi, I have an ACF Options Page that stores site-wide information such as, business name, address, phone and email address.
What I’d like to do is reference this information in a Gutenberg block.
I’m not using ACF Block but instead building in the standard WP way which I’m now quite confident doing (e.g. https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/writing-your-first-block-type/)
Referencing the information in the frontend using PHP is easy, but I can’t find a way of referencing the information in JSX so it displays in the block when editing a page in the backend. The block only needs to display the information, it doesn’t need to make any changes or store the information – the ACF Options Page will take care of that.
Does anyone know of a way of doing this? Hopefully it’s a silly question to ask and easy to answer.
First thanks for ACF, it’s cool
I got this funtion php code :
global $post;
$current_id = $post->ID;
$output = '<div>' . get_template_part('get_search_form') . '</div>';
$output .= '<h3 class="text-center">Ou explorez le contenu grâce aux tags...</h3>';
$output .= '<p class="font-italic text-center text-italic">Par format, par public ou par série !</p>';
$output .= '<div id="filters" class="select_filters mb-30">';
$output .= '
<div class="select-primaire">
<span>
<select id="thematique_select" class="s-hidden">
<option></options>
</select>
</span>
</div>';
I got a select named “thematique_article” in a ACF field group named “filtres_article”. I cant get the options of the ACF select and put them into my front select. Can someone help me ? !
Hi,
I’m working on a site template where the owner of the website should be able to add/remove items from a repeater – works fine! The issue is, that on each repeater item there’s a button. When the button is clicked, a modal pops up and in there is a slider with images from a gallery assigned to each repeater item. This also works but the “display none” still goes in all the slides but is not visible and returns an empty slide (the image is still visible in the console).
What can it be?
I’ll try to paste the code below.
<?php
/**
* Template Name: Products */
$card_counter = 0;
?>
<?php get_header(); ?>
<div class="page-margin">
<h1 class="goldtext"><?php echo get_the_title(); ?></h1>
<div class="center"><?php the_content(); ?></div>
<div class="whitespace"></div>
<?php if ( have_rows('products') ) : ?>
<div class="product_card">
<?php while ( have_rows('products') ) : the_row(); ?>
<?php
$product_name = get_sub_field('product_name');
$btn_text = get_sub_field('btn_text');
$background_image = get_sub_field('background_image');
$product_description = get_sub_field('product_description');
$images = get_sub_field('product_gallery');
?>
<div class="cta_card_inner product_card_inner" style="background-image: url(<?= $background_image['url']; ?>)">
<div class="cta_card_inner_background">
<h3 class="goldtext"><?= $product_name; ?></h3>
<div class="ctadetails">
<p class="cta_description"><?= $product_description; ?></p>
<button class="primary-btn center openModal">
<span class="button-leftpart-primary">
<?= $btn_text; ?>
</span>
<span class="button-rightpart-primary">
<p class="button-content-right">🡒</p>
</span>
</button>
</div>
</div>
</div>
<div class="modal productsPopupModal" id="card-<?php echo $card_counter;?>">
<div class="products-popup productsPopup " id="cards-<?php echo $card_counter; $card_counter += 1; ?>">
<div class="products-popup-heading">
<button type="button" class="products-close-popup goldtext closeModal">✖</button>
<h3 class="goldtext center"><?= $product_name; ?></h3>
</div>
<div class="products-slideshow">
<?php if($images): ?>
<?php foreach( $images as $image ): ?>
<img />" />
<?php endforeach; ?>
<?php endif; ?>
<button class="slideshow-arrow-left goldtext" onclick="plusDivs(-1)">❮</button>
<button class="slideshow-arrow-right goldtext" onclick="plusDivs(1)">❯</button>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
<?php get_footer(); ?>
// MODAL
const readMoreBtns = document.querySelectorAll(".openModal");
const closeBtns = document.querySelectorAll(".closeModal");
var cardCount = 0;
readMoreBtns.forEach((btn) => {
let productsPopupModal = "card-" + cardCount;
let productsPopup = "cards-" + cardCount;
btn.addEventListener("click", () => {
document.querySelector("#" + productsPopupModal).style.display = "block";
document.querySelector("#" + productsPopup).style.display = "block";
});
closeBtns.forEach((btn) => {
let productsPopupModal = "card-" + cardCount;
let productsPopup = "cards-" + cardCount;
btn.addEventListener("click", () => {
document.querySelector("#" + productsPopupModal).style.display = "none";
document.querySelector("#" + productsPopup).style.display = "none";
});
});
cardCount += 1;
});
// SLIDESHOW
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs((slideIndex += n));
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("productsSlideImg");
if (n > x.length) {
slideIndex = 1;
}
if (n < 1) {
slideIndex = x.length;
}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex - 1].style.display = "block";
}
I’m facing an issue with custom fields for users, even though I think that’d happen for posts too.
I have a group “custom_fields” and within this group, there’s a multi-select whose key is “user_lang_spoken”.
This multi-select is pulling a custom taxonomy and it will return a list of term IDs.
Ok, so far so good and easy to understand. This is my custom loop to pull users:
$speaks = 5; // 5 = Spanish (That's the term name)
$args = array(
'fields' => 'ids',
);
if ($speaks) {
$args['meta_query'][] = array(
'key' => 'custom_fields_user_lang_spoken',
'value' => $speaks,
'compare' => 'LIKE',
);
}
$members = get_users($args);
#1 – You’ll see that I’m using ‘value’ => $speaks, and this is pulling all users who speak language 5 or language 55 (which is not ideal). This could actually work if it wasn’t numbers because we wouldn’t have a partial match, but I need them as IDs.
#2 – However, I found another topic where you guys say it returns serialized data and you recommend wrapping the value with quotes: ‘value’ => ‘”‘.$speaks.'”‘, and this is true, I’ll retrieve only users who speak language 5, but for that I need to MANUALLY update the user in the admin (without changing anything). Otherwise, I wont be able to see the user in this case.
I think this is an actual issue, it won’t happen often because people may be returning strings instead of IDs and by doing that, the chances of a partial match is rare. Also, if they are using IDs, they might have different IDs such as 2918, 9812, 5839… which again, would be rare.
However, that partial match will happen with lower numbers: 1 -> 12, 3 -> 32…
I don’t know what else to do, I tried some work around to force a user update on the frontend but it doesn’t seem to have the same impact as manually clicking on “Update user”.
Thanks!
I am struggling to find an answer to this issue, and I am not sure what I am doing wrong. I have looked at several examples of adding JS files to the block.json, and I am doing it the same way as the examples. I am using the 2021 WordPress theme as my parent theme and the latest version of WordPress/ACF. I have registered the block, the CSS files show up in the inline CSS, but my scripts are not working/showing up at all. Any help is appreciated, thank you!
Block.json
{
"name": "acf/gallery-slider",
"title": "Gallery Slider",
"description": "A custom Gallery Slider.",
"style": [ "file:./owl.carousel.min.css", "file:./owl.theme.default.min.css", "file:./gallery-slider.css" ],
"script": "file:./odm-owl-carousel.js",
"category": "ODM",
"icon": "cover-image",
"keywords": [ "ODM", "gallery", "slider", "owl" ],
"acf": {
"mode": "preview",
"renderTemplate": "gallery-slider.php"
}
}
odm-owl-carousel.js
window.onload = function() {
setTimeout(function() {
console.log("working");
}, 2000); // 2000 milliseconds = 2 seconds
};
jQuery(document).ready(function($) {
console.log('odm-owl-carousel.js loaded 1');
jQuery('.owl-carousel').owlCarousel({
loop: true,
margin: 0,
responsiveClass: true,
responsive: {
0: {
items: 1,
},
875: {
items: 3, // Display 3 items on screens wider than 768px
}
},
nav: true, // Enable navigation
navText: ['<img src="/wp-content/uploads/2023/08/arrow-orange-light.png" alt="arrow" />', '<img src="/wp-content/uploads/2023/08/arrow-orange-light.png" alt="arrow" />'], // Custom nav icons
center: true, // Center the active item
onInitialized: function(event) {
// Add "large" class to the initially centered item
var centerItem = jQuery(event.target).find('.owl-item.center');
centerItem.addClass('large');
},
onTranslated: function(event) {
// Remove "large" class from all items
jQuery('.owl-item').removeClass('large');
// Add "large" class to the currently active (center) item
var centerItem = jQuery(event.target).find('.owl-item.center');
centerItem.addClass('large');
}
});
});
I’ve been struggling to find a solution to the below error. I’ve been in contact with Elementor pro developers but they’re unable to help, as I’ve created some custom shortcode functions (in functions.php) which is outside their support scope ?
PHP 8.1
Wordpress 6.3.1
Elementor Pro 3.15.1
ACF Pro 6.2.0
[01-Sep-2023 02:54:06 UTC] PHP Warning: Undefined array key 1 in /home/.../public_html/wp-content/plugins/elementor-pro/modules/dynamic-tags/acf/tags/acf-text.php on line 33
[01-Sep-2023 02:54:06 UTC] PHP Warning: Undefined array key 0 in /home/.../public_html/wp-content/plugins/elementor-pro/modules/dynamic-tags/acf/tags/acf-text.php on line 33
Firstly – all of the pages that use ACF and my custom queries/shortcodes all work as expected. The problem is that these errors are being generated evry few seconds so the log file grows exponentially over a few hours.
I have several ACF text fields – some are used in repeater fields and others are not. They are all edited via 2 options pages.
Our homepage uses a post loop that contains editor and author info that includes an ACF text field (not part of a repeater) guest_author
Code for homepage Guest Author:
function custom_author($post_id) {
global $post_id;
if(is_front_page() || is_post_type_archive() && (get_field( 'guest_author', $post_id ) != "")){
$author_value = get_field( 'guest_author', $post_id );
return ( '<span style="color:#000;">By: </span><span style="color:#f70d28;">'.$author_value.'</span><br>');
// }
} else {
$author_id = get_the_author_meta( 'ID' );
$author_value = get_the_author_meta('display_name', $author_id);
}
return $author_value;
}
add_filter('the_author', 'custom_author', 10, 2);
My repeater fields are a simple format that output rows with text and href as below:-
function voicepage_elementor_shortcode_resources( ) {
if (have_rows( 'voice_resources', 'voice_options' )):
while (have_rows( 'voice_resources', 'voice_options' )): the_row();
$restext = get_sub_field('field_64b5d8fc89d87'); // Also works using the field name resource_title in place of field key
$reslink = get_sub_field('field_64b5d91589d88'); // Resource link - name or key works
echo '<div class="resourcelist"><div class="resourcetext"><p><a href="'.$reslink.'">'.$restext.'</a></p></div><div class="resourceicon"><i class="far fa-arrow-alt-circle-right"></i></div></div>';
endwhile;
endif;
}
add_shortcode( 'voice_resources_output', 'voicepage_elementor_shortcode_resources');
Really appreciate any directions I should take to get rid of these errors, apart from turning them off.
TIA
Hey there.
I’m trying to do a “reverse lookup” I believe it is called. I have a post type “plants” with a Gallery field “main_info_images”. The images themselves have ACF fields, one of which is “image_meta_image_id” (this is not the post ID of the image).
I need to find the plant that has a gallery image with a certain “image_meta_image_id” number.
Some of the images were initially uploaded to a different post type, so not all are “attached” to the plant. From what I understand, the image stays attached to its original “parent” post.
I think I need to do some sort of nested meta_query? Or perhaps two queries — one that searches through all the images by “image_meta_image_id” and returns the post_id of that image, then use that image’s post_id to find the plant that has that image in its Gallery?
This is what I have to try to get the image’s post_id.
Thanks so much for any help!
$args = array(
'numberposts' => -1,
'posts_per_page' => 2,
'post_type' => 'attachment',
'meta_query' => array(
array(
'key' => 'image_meta_image_id',
'value' => '"'.$image_meta_image_id.'"',
'compare' => 'LIKE'
)
)
);
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ):
while( $the_query->have_posts() ) : $the_query->the_post();
$the_image_id = get_the_ID();
echo "THE IMAGE ID: ".$the_image_id;
endwhile;
endif;
wp_reset_query();
Hi, very new to ACF and I’m trying to get the values (i think) of the field group choices.
I have the choices:
example-student : Student
example-teacher : Teacher
example-principal : Principal
I want to get the second value of these choices (Student, Teacher, Principal) instead of the first.
I’ve tried a number of things looking at the get_field
documentation but I can’t seem to get what I need.
Here’s my code:
$people= get_field('people');
if (is_array($people) && count($people))
{
print('<h5>More information for...</h5>' . "\n" . '<ul>' . "\n");
foreach ($people as $slug)
{
print(' <li><a href="/' . $slug . '/" class="audience ' . $slug . '">' .
ucwords(str_replace('-',' ', $slug)) . '</a></li>' . "\n");
}
print('</ul>' . "\n");
}
This will get me a list of links with Example Student
.. etc. instead of just Student
.. etc.
Thanks,
Hi community – I’d like to change a few ACF fields to live on a standalone Options page instead of displaying on a specific post.
I am currently able to update their values via POST requests to the /wp-json/wp/v2/pages/$POST_ID endpoint. However, when I moved the fields to an options page, I wasn’t sure how to go about continuing to update their values via a POST/REST API request. Is that something that is possible? If so, what are the endpoints we should use for that?
Thank you!