Use MB Block php callback function to render CPT posts with MB blocks inserted

Support › MB Blocks › Use MB Block php callback function to render CPT posts with MB blocks inserted

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #43666
    DaveDave
    Participant

    I have a solution that requires me to use a MB Block inserted into page or template to render CPT posts that use Gutenberg Editor.

    The problem is that it appears I must use apply_filters('the_content', get_the_content()) to render them. However, using this, I assume causes the blocks being rendered to think current post id ($post_id) is the id of the CPT post ID where they were initially inserted. Is there a way to achieve this without specifically modifying the original MB blocks php callback?

    The only work around I have now, is to use a shortcode to insert them, where I can directly use get_the_content(). In this case they will correctly know the current page id ($post_id).

    Could you please advise if this is a global WordPress issue or if it is specific to using Metabox blocks in Block themes?

    Any help or recommendations much appreciated.

    thanks in advance.

    #43673
    PeterPeter
    Moderator

    Hello Dave,

    Can you please give some examples/code of your case so I can understand the question better?

    If you want to create a block that shows a list of CPT, simply, you can use the callback function and add a custom query to show posts.
    https://docs.metabox.io/extensions/mb-blocks/#render_callback
    https://developer.wordpress.org/reference/classes/wp_query/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.