Blocks are not printed if the content of the post is returned through get_post_field
Hi! I created a few blocks using the plugin earlier on (it's really great!) but noticed that they are not echoed if the content of the page\post is returned using using the get_post_field function.
Here's a very summarised version of the relevant code:
$id = get_the_ID(); $wp_content = get_post_field("post_content",$id); echo $wp_content;
The "normal" content of the post is displayed correctly, the custom blocks are not.
Displaying the content in an alternative way (e.g. using the loop) makes them appear correctly, on the other hand.
Cheers!
Hi @5g4kQNpw, Thanks for bringing this up, and for using Block Lab.
Where is get_post_field("post_content",$id); running, and is there a reason it can't run in the loop?
I also see the issue you mentioned, and it looks like it also exists for another dynamic block, the Latest Comments block.
If by chance you haven't used it, there's a Block Lab function block_field() that can get or echo a specific Block Lab field.
Hey!
I had no particular reason not to use the loop - in fact I switched to it and now everything is working perfectly (and I am very much enjoying my custom blocks) 👍
I opened the issue for your reference, mostly.
Other than that, using block_field() had no effect, sadly: the content wouldn't still be echoed.
Take care!
I opened the issue for your reference, mostly.
Thanks, I appreciate it. I also saw the issue once you brought it up, so it's helpful to know that.
Other than that, using block_field() had no effect, sadly: the content wouldn't still be echoed.
Ah, OK. Yeah, block_field() is intended for use inside the block template, I forgot about that.