Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Blocks are not printed if the content of the post is returned through get_post_field #468

Open
forcedefrappe opened this issue Nov 3, 2019 · 3 comments

Comments

@forcedefrappe
Copy link

forcedefrappe commented Nov 3, 2019

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!

@kienstra
Copy link
Collaborator

kienstra commented Nov 3, 2019

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.

@forcedefrappe
Copy link
Author

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!

@kienstra
Copy link
Collaborator

kienstra commented Nov 4, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants