Site logo

[Support request] Elements (Block): How to display a button depending on a custom field?

Home Forums Support [Support request] Elements (Block): How to display a button depending on a custom field?

Home Forums Support Elements (Block): How to display a button depending on a custom field?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1886916
    Sascha

    Hi

    I use Metabox to create custom fields for a custom post type “projects”.

    One of the fields is URL-type, which is used to redirect to an external project-site.

    I have created a button as a Block-Element and entered the custom-field-shortcode as the button-name. But since not all the “projects” have this field filled out, which would result in an “empty” button, which doesn’t look nice.

    Is it possible to display this button on the frontend only when the custom-field is not empty?

    Thank you in advance and kind regards,
    Sascha

    #1887057
    David
    Staff
    Customer Support

    Hi there,

    do you require the custom-field-shortcode ?
    If you select the Button, and click the Dynamic options in the toolbar, you can select Dynamic Text Type > Post Meta, then add your custom field name in the Post Meta Name field. This should pull in your custom field name, and if its empty it won’t display.

    If the Custom Field Shortcode is required, then add the button inside a container block, in it sidebar settings you have: Remove container condition which you can set to a Post Meta field to define if its displayed or not.

    #1887348
    Sascha

    I have to admit that I haven’t digged into Dynamic features of GPP yet, so thank you a lot for reminding me to use them!

    Now I’d like to know, how to apply the content of a custom-field (type: URL, id: website_url) to the button. I have tried to apply [rwmb_meta id=”website_url”] (this is schema for metabox shortcodes), but it does not work and instead to the URL of the custom field, the button will open the URL of the post, where the button is placed.

    Any idea about how to solve this?

    #1887360
    David
    Staff
    Customer Support

    As long as you’re using a GenerateBlocks button, you cans select the Dynamic option in the toolbar. Theres options to set the Dynmaic Text type and the Dynamic Link type. Set both of them to Post Meta, and add you Custom Field Name in the field provided.

    No shortcodes required.

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