Home › Forums › Feature Requests › Get custom field inside query loop block › Reply To: Get custom field inside query loop block
Hi Guys – just want to share my workaround idea here…
assuming you want to place a custom field value before (or after) the post-title block in the loop template, you can give the block a unique classname like in my case “company” and then look for that classname in the following code you need to put in your functions.php
add_filter( 'render_block_core/post-title', function( $block_content, $block ) {
if(!empty($block["attrs"]["className"]) && $block["attrs"]["className"] != "company") return $block_content;
return sprintf("<div style='margin-bottom:%s'><strong>%s</strong></div>%s","10px",get_field("company"),$block_content);
}, 10, 2 );
thats a pretty robust solution because it uses core code. In my case i need to output the custom field “company” before the post title in of one post in the loop. This will work for the frontend only!
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.