You will need to adapt the following to match your fields etc:
<?php
$args = array(
'post_type' => 'stockist',
'order' => 'ASC',
'order_by' => 'title',
'posts_per_page' => -1,
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
$the_id = get_the_ID();
$location = get_field( 'company_address' );
$link = get_field( 'company_link' );
$phone = get_field( 'company_phone' );
$country = get_field( 'country_name' );
$logo = get_field( 'company_logo' );
$size = 'productsml';
if ( ! empty( $location ) ) {
?>
<div class="acf-map">
<div class="marker text-center" data-lat="<?php echo esc_attr( $location['lat'] ); ?>" data-lng="<?php echo esc_attr( $location['lng'] ); ?>">
<?php
if ( $logo ) {
echo wp_get_attachment_image( $logo, $size );
}
?>
<h3><?php the_title(); ?></h3>
<?php
if ( $location ) {
$address = '';
foreach ( array( 'street_number', 'street_name', 'city', 'state', 'post_code', 'country' ) as $i => $k ) {
if ( isset( $location[ $k ] ) ) {
$address .= sprintf( '<span class="segment-%s">%s<br /></span>, ', $k, $location[ $k ] );
}
}
$address = trim( $address, ', ' );
?>
<p><?php echo esc_html( $location['address'] ); ?></p>
<?php
}
?>
<?php if ( $phone ) { ?>
<p><?php echo esc_attr( $phone ); ?> </p>
<?php } ?>
<?php if ( $link ) { ?>
<a class="button" href="<?php echo esc_url( $link ); ?>">Visit Website </a>
<?php } ?>
</div>
<?php
}
endwhile;
endif;
?>
This should fix this:
acf_register_block_type(array(
'align' => 'full',
'supports' => array(
'align' => array('full'),
'align' => false,
),
));
you need to add the ‘align’ => false, to hide the alignment icon.
A non-JS option:
Just swap out ‘company_detail’ for the name of your WYSIWYG field.
And set/alter the length of the excerpt by changing the ’32’
<p>
<?php
$raw_content = get_field( 'company_detail' );
$trimmed_content = wp_trim_words( $raw_content, '32' );
$clean_excerpt = apply_filters( 'the_excerpt', $trimmed_content );
echo esc_attr( $clean_excerpt );
?>
</p>
Thanks @daniel-buth That’s where I had went wrong…
Not seeing the bark on the trees.
Thanks Man, appreciate it.
Was pulling the hair out for a while there.
Thanks @daniel-buth That’s how I had the block setup originally.
In ACF, it’s set to Post Object
already.
I have created a gist of the amended code:
Gist
Now what I am getting is ALL the posts are displaying the content of the page they are being shown on. And not bringing in any of the selected items from the ACF Relationship field block.
Hi, I think @matthewfarlymn ‘s solution is what I am needing, but I am not 100% on how to make it work for what I need.
I have a CPT – Events with two taxonomies (event_category) – upcoming & past events.
I am trying to have them listed in order of the event date.
For upcoming events, the one happening soonest first – to the furthest away.
And for past, then the most recent first. Etc..
The thing is, the event date is entered in the post via an ACF field within a block in each post.
My current template only shows the posts if I remove or comment out the
'meta_key' => array( $date ),
Template File: GIST
How can I use the solution above, and integrate it with the template?
I tried dropping it into functions.php, but got an error (had edited to include block name & field).
Any guidance would be greatly appreciated.
Resolved with the following:
<?php
$link = get_field( 'supporterlink', get_the_id() );
if ( $link ) : ?>
<a href="<?php echo esc_url( $link ); ?>">
<?php endif; ?>
<img role="img" src="<?php the_post_thumbnail_url( 'medium' ); ?>" alt="<?php the_title(); ?>"/>
<?php if ( $link ) : ?>
</a>
<?php endif; ?>
See updated Gist:
GIST
The image does not seem to be showing, so here’s a direct link:
Screenshot
Resolved…
Here’s the solution for anyone searching for the same problem:
<?php
$role = the_field( 'role' );
$post = get_post();
?>
<h6><?php the_field( 'role', $post ); ?></h6>
I thought the following post had the solution, but it didn’t work.
https://support.advancedcustomfields.com/forums/topic/cannot-access-acf-field-value-for-cpt-post-when-called-via-gutenberg-block/
It looks like you may have found the solution for an issue I was having earlier today @tanmccuin , Thank You!
Here’s the resulting output:
https://www.dropbox.com/s/m7wu8dz1crskler/Screenshot-2019-09-04-at-18.19.12.jpg?dl=0
Not ideal, but I found this, which I have got working for me.
https://www.billerickson.net/disabling-gutenberg-certain-templates/
I came to the forums in the hope of finding a solution for this exact same issue.
ACF: 5.8.0-beta4.1
WP: 5.1.1
**Resolved**
See: https://gist.github.com/macgraphic/e844ccb112130136f2ecf0baa9e8a295
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.