Hi All,
I’m just wondering if anyone had any joy with an ACF block and Bootstrap 5’s carousel scripts?
Any help would be much appreciated!
Thanks
Don’t worry, I’ve solved it.
I foolishly had not passed the post ID during an include – d’oh!
Once you add the code example, you need to amend the WYSIYG field and select the newly named toolbar.
Just in case you weren’t aware!?
You could look to try something like:
$args = array(
'post_type' => 'page',
'meta_query' => array(
'relation' => 'AND',
'template_clause' => array(
'key' => '_wp_page_template',
'value' => 'unit.php',
),
'status_clause' => array(
'key' => 'status',
'compare' => 'EXISTS',
),
),
'orderby' => array(
'status_clause' => 'DESC',
),
);
$loop = new WP_Query( $args );
As per the WP Docs
HI @swifty
I’d be more inclined to use a True/False field. You can then do something like:
<?php if ( get_field( 'display_watercooling' ) ): ?>
Your image goes here
<?php endif; ?>
So using an True/False field called ‘Display Watercooling’, if it’s then ticked, the predfined image is shown. If it’s not ticked, you could either show another image (add an ELSE clause) OR not show an image at all.
If you convert the value to lowercase and convert any spaces to hyphens, this would be the same as returning the slug.
Would that work?
HI @dagdal1967
If you check the acf query examples page, you should be able to achieve what you need. Just set the post type to products
HI @vex700
The best solution I’ve ever found is using WP All Import. They even have an ACF plugin to make it easier. You basically upload your file and map the fields.
Whilst not free, it’s well worth the investment!
If you can get the attachment ID, you might be able to use:
wp_delete_attachment( $attachment->ID, 'true' );
Thanks @hube2
I ended up going a slightly different route, combined with this extremely helpful post
After adjusting to my needs, it works a treat!
I’d be inclined to use a true/false field. You can then do something like:
<?php if ( get_field('position_open') ): ?>
Add button code here
<?php endif; ?>
Just change position_open to the name of your true/false field
You can also check this post on how to get all values from a select field
Hi
Check your code.
new \WP_Query
has a random backslash
'orderby' => 'meta_value date',
you’re ordering by a date field?
You could check the ACF docs on querying by custom fields. The WP Docs show how to order by custom fields
Is the select field set to return a single value or multiple values?
The code differs, check the docs for code examples.
Hmm,
If events is the custom post type, then this isn’t right:
'category_name' => 'events',
Your meta query seems to have 2 values you’re passing in:
'meta-value' => $value,
'value' => $today,
What if you combine everything into one query, something like:
$args = array(
'post_type' => 'event_cpt',
'posts_per_page' => 6,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_start_date',
'value' => $today,
'type' => 'DATE',
'compare' => '>=',
),
),
);
$args['meta_query'] = array( 'relation' => 'AND' );
$args['tax_query'] = array(
'relation' => 'OR', #AND
array(
'taxonomy' => 'academic_programs',
'field' => 'term_id',
'terms' => $academic_programs_id
),
);
$args['tax_query'] = array(
'relation' => 'OR', #AND
array(
'taxonomy' => 'event_type',
'field' => 'term_id',
'terms' => $event_type_id
),
);
$query = new WP_Query( $args );
if( $query->have_posts() ) :
while( $query->have_posts() ): $query->the_post(); ?>
<span><?php $date = get_field('event_start_date');
$starttime = get_field('event_start_time');
echo $date . " - " . $starttime; ?></span></br>
<?php endwhile; wp_reset_postdata();
endif;
Code is totally untested.
Also worth adding debugging code in:
global $wpdb;
// Print last SQL query string
echo $wpdb->last_query;
// Print last SQL query result
echo $wpdb->last_result;
// Print last SQL query Error
echo $wpdb->last_error;
You can see what the output of your query contains, it may then point you in the right direction
As far as I know, the ACF frontend form doesn’t reload the page. You can opt to redirect on submission
Or you could look to use something like Gravity Forms, you can opt to create a post based on the form (you need the developer licence), plus handles a lot of the work for you. I know for certain the page doesn’t reload, unless you want it to. I used this for several sites and works well!
You could use the Text Editor/WYSIWYG field
OR
You could use 3 fields
Textarea – to create the text
Textfield – to create the link text
URL – to handle the link
The latter would need more coding to combine the fields
Can you show your code please?
And to clarify, the taxonomy is called floor4
This is linked to a CPT of flat4
The ACF field is called hover and it’s this value you’re trying to get?
Does this work:
global $wp_query;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => -1,
'post_type' => 'flat4',
'paged' => $paged,
'fields' => 'ids'
);
$wp_query = new WP_Query($args);
if ($wp_query->have_posts()) :
while ($wp_query->have_posts()) : $wp_query->the_post();
$taxonomies = get_terms( array(
'taxonomy' => 'floor4',
'hide_empty' => false
) );
if ( !empty($taxonomies) ) :
foreach( $taxonomies as $category ) {
$hover= get_field('hover', 'term_' .$category->term_id );
echo $hover;
}
endif;
endwhile;
endif; wp_reset_query();
What code do you have?
Maybe I’ve misunderstood.
This loops categories:
<?php
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC'
) );
foreach( $categories as $category ) {
$category_link = sprintf(
'<a href="%1$s" alt="%2$s">%3$s</a>',
esc_url( get_category_link( $category->term_id ) ),
esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
esc_html( $category->name )
);
echo '<p>' . sprintf( esc_html__( 'Category: %s', 'textdomain' ), $category_link ) . '</p> ';
echo '<p>' . sprintf( esc_html__( 'Description: %s', 'textdomain' ), $category->description ) . '</p>';
echo '<p>' . sprintf( esc_html__( 'Post Count: %s', 'textdomain' ), $category->count ) . '</p>';
}
This loops taxonomies:
<?php if( $categories = get_terms( array( 'taxonomy' => 'floor4' ) ) ) :
foreach( $categories as $cat) :
$hover= get_field('hover', 'term_' .$cat->term_id );?>
<?php echo $hover; ?>
<?php endforeach;
endif;
?>
if you echo $cat->term_id;
does it show a value? If so, is it the right one?
I assume ‘hover’ is the taxonomy name?
To add to this, are you using WooCommerce for products and orders?
If so, a pseudo answer would be something like:
Look at transition_post_status
When the post is updated, you need to get the post ID
You then need to Get List of WooCommerce Customer Emails Who Purchased a Specific Product
Now you have the customer email, you can use wp_mail()
Hope that helps!
What about:
<?php
$term = get_field(‘hover’,’floor4_’ . $cat->term_id);
echo $term;
Code untested and assume $cat->term_id has a value
Could you not condense the query down to something like:
function listing_expiry_date() {
$args = array(
'post_type' => array('post_type_listings'),
'posts_per_page' => -1,
'post_status' => 'publish',
'orderby' => 'post_date',
'order' => 'DESC',
'date_query' => array(
array(
#'after' => 'January 1st, 2013',
'before' => array(
'year' => date("Y"),
'month' => date('m'),
'day' => date('d'),
),
'inclusive' => true,
),
),
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
# change the post status
$postdata = array(
'ID' => $post->ID,
'post_status' => 'expired'
);
wp_update_post($postdata);
}
wp_reset_postdata();
}
}
Code untested!
I assume the value already exists?
What’s your code so we can take a look and try to help?
Do any other sub fields work or is it just one?
Are you passing the post ID to the repeater in your Ajax?
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.