Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Change the way Generateblocks accesses post_meta

  • I was using a dictionary template to display custom fields, but I realized that it needs to be in the postmeta table to be read, and I use ACF with custom table to store the data, so I’m having trouble getting generateblocks to display the custom fields that are not present in the postmeta table.

    I had a similar problem with Rank Math, the support solved changing the code get_post_meta( $this->args->ID, $name, true ) for get_field( $name )

    Is there anything I can do similarly on Generateblocks?

  • Hi there,

    Which plugin did you utilize for storing ACF data in a custom table? There might be a feature within the plugin that enables retrieval of data from this custom table, which could be beneficial for use in GenerateBlocks.

  • The Custom Post plugin is ACF, the custom table plugin is ACF to Custom Database Tables by Abhishek Satre.

    Note, if you are going to do tests, natively even if you install the custom table plugin WordPress continues to save the Custom_field in postmeta, in this case I disabled this to avoid weight in the postmeta using a functions. I used:

    add_filter(‘acf_ct/settings/store_acf_values_in_post_meta’, ‘__return_false’);

  • Hi there,

    at this time GB can only retrieve from standard post meta and some ACF fields using get_field ( if using GB Pro ).

    To target a different fields saved in other tables would require a different solution.
    For exmaple: Does it work with an ACF Shortcode ?

  • Yes, I use ACF_FIELD shortcode and it works normal, and as I mentioned, the similar problem with RankMath was solved using get_field. In this case, RankMath could not pull the postmeta from the custom table, it returned blank the %customfield(name)% used in the Meta and Schema.

    What do you mean by get_field in GB Pro? I can currently get GB’s QueryLoop to filter through custom fields using a function created to put in the CSS class, but not display it through the dynamic post_meta in the block settings.

  • What do you mean by get_field in GB Pro?

    Means GB Pro uses get_field() to fetch the ACF data. In your case, it might require the GB Pro plugin.

  • I’m using a friend’s GB Pro, but it seems that post_meta of the blocks of conditions and others is still not working.

  • but it seems that post_meta of the blocks of conditions and others is still not working.

    what do you mean by blocks of conditions and others? Can you specify some actual cases?

  • Example, I use QueryLoop Block to display articles that are related to the article in question, for example, I have custom_post of words and a custom_post of sentences, if the title of the custom_post is found in the title of the sentence I display it along with custom_fields of the sentence, but these custom_fields do not appear because they are not in post_meta, I display these custom fields using Generateblocks title and the dynamic fill post_meta. The conditions was not to display if it didn’t have a custom_field, so it never ends up displaying because it can’t find the custom_field in postmeta.

  • I’ve read through the plugin’s documentation and it appears they have provided a function to retrieve data from the custom table. You can refer to it here:
    https://acf-custom-tables.abhisheksatre.com/docs/functions/get-custom-table-field/

  • I think you got it wrong, the ACF already recovers the data from the custom table, it works perfectly all the shortcodes and even functions.php that use get_field(), the problem is only the Generate Blocks.

  • To cover what GB does:

    GenerateBlocks Free, can only retrieve the current post meta using get_post_meta

    GenerateBlocks Pro, simple ACF Fields that have the Show in REST API enabled should show in the Dynamic Data -> Post Meta field options. Choosing one of those will use the get_field function.

    GenerateBlock Pro, Remove Container Condition only works with get_post_meta.

    So if there is a simple ACF Field that GB can find it should work exactly as the ACF Shortcode
    But the Remove Container Condition will not work with a field that is not visible via get_post_meta

    And currently there is no way to change that behaviour. For now you will need to use ACF Shortcodes or render_block etc. In the future we plan to add tighter integration with ACF.

    If you need help with removing a container based on the state of an ACF Field then this snippet will help as an example of how to do it with render_block:

    
    add_filter( 'render_block', 'remove_block_content_if_condition_empty', 10, 2 );
    
    function remove_block_content_if_condition_empty( $block_content, $block ) {
        // Check if we are not in the admin and the block has the CSS class 'condition-one'
        if ( !is_admin() && isset( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'hide-on-condition' ) !== false ) {
            // Check if the condition is empty
            if ( empty( get_field('condition') ) ) {
                // If condition is empty, remove the block content
                return '';
            }
        }
        // If in admin or condition is not empty, return the block content as it is
        return $block_content;
    }
    
  • I get it, I created a condition via Shortcode, it worked well. So the dynamic information works using get_field. I didn’t understand well translating into Portuguese, REST API? Acho que não funcionou aqui usando Dynamic Data.

  • If the Custom Field is available in the current post editor then it will show in the list – see here:

    https://app.screencast.com/DQisugVLwyYso

    As long as thats working there, then it means GB can find the ACF Field name view REST and if possible will use the get_field function.

  • So this option uses get_field? Let me see if I understand, he can get only the existing value in the current post, if I’m in a query will he be able to get the value of the query from another post?

  • When you do get_field() without specifying any ID it will use the current post.
    So if you use an ACF Field in a query loop it will look at the current post in the loop to get the value.

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