Home › Forums › Front-end Issues › PHP code for ACF inside WordPress add_filter
Hello everyone!
I have a problem with my site, i need to insert a field at a specific point on my WordPress website and the developer of the theme gave me this snippet for it:
add_filter(
'hivepress/v1/templates/vendor_view_page/blocks',
function( $blocks, $template ) {
return hivepress()->helper->merge_trees(
[ 'blocks' => $blocks ],
[
'blocks' => [
'page_content' => [
'blocks' => [
'custom_listings_text' => [
'type' => 'content',
'content' => 'Your content here',
'_order' => 1,
],
],
],
],
]
)['blocks'];
},
1000,
2
);
It works perfect, but my problem is that i can’t get my head around how i change the ‘Your content here’ so i get the information of my ACF.
I know that the “normal” code is:
<?php if( get_field('text_field') ): ?>
<h2><?php the_field('text_field'); ?></h2>
<?php endif; ?>
But how do I “insert” this into the snippet?
I’m sorry if this isn’t the right forum or if there’s a really simple solution to this, but as a complete beginner I’ve been dealing with this problem for days and I can’t find a solution.
add_filter(
'hivepress/v1/templates/vendor_view_page/blocks',
function( $blocks, $template ) {
if (get_field('text_field')) {
$content = get_field('text_field');
return hivepress()->helper->merge_trees(
[ 'blocks' => $blocks ],
[
'blocks' => [
'page_content' => [
'blocks' => [
'custom_listings_text' => [
'type' => 'content',
'content' => $content,
'_order' => 1,
],
],
],
],
]
)['blocks'];
} // end if
},
1000,
2
);
You must be logged in to reply to this topic.
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.