Support

Account

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!