pods-framework / pods

The Pods Framework is a Content Development Framework for WordPress - It lets you create and extend content types that can be used for any project. Add fields of various types we've built in, or add your own with custom inputs, you have total control.
https://pods.io/
GNU General Public License v2.0
1.07k stars 264 forks source link

Divi 4.0 - Pods custom fields not displaying in dynamic fields in divi builder #5565

Closed christianmarth closed 4 years ago

christianmarth commented 4 years ago

Describe the bug When I have a custom post type and custom fields created with Pods, I am unable to access them in the Divi Theme Builder using the Divi dynamic fields

To Reproduce Steps to reproduce the behaviour:

  1. Start with a fresh WordPress Installation
  2. Install Divi Theme 4.0
  3. Install Pods
  4. Using Pods, create a custom post type (e.g Cars)
  5. Create custom fields for the newly created custom post type (e.g. Make, Model, Price)
  6. Go to Divi Theme Builder
  7. Create a new template for all {post type} (in this example all cars) This will create the template for single-{post-type}.php
  8. Add custom body
  9. Build custom body
  10. Build from scratch
  11. Add a new full width row
  12. Insert text module
  13. Hover over the text input area to show the database icon with the plus symbol indicating use dynamic content
  14. Observe that the pods custom fields for our custom post type do not appear on the list of dynamic fields available in Divi

Expected behaviour When a custom post type and custom field created with Pods exists, then this custom field is displayed in Divi Theme Build Dynamic Content option

Screenshots A demonstration of the issue can be seen on the video below https://youtu.be/8RE17y_JqYY

Pods Version

Pods Version 2.7.16.2 and Divi Version: 4.0.9

WordPress Environment

`

wp-core

version: 5.3.2 site_language: en_US user_language: en_US timezone: +00:00 permalink: /index.php/%year%/%monthnum%/%day%/%postname%/ https_status: true user_registration: 0 default_comment_status: open multisite: false user_count: 1 dotorg_communication: true

wp-paths-sizes

wordpress_path: /home/customer/www/helpleh.com.sg/public_html wordpress_size: 45.13 MB (47326071 bytes) uploads_path: /home/customer/www/helpleh.com.sg/public_html/wp-content/uploads uploads_size: 0.00 B (0 bytes) themes_path: /home/customer/www/helpleh.com.sg/public_html/wp-content/themes themes_size: 37.16 MB (38969272 bytes) plugins_path: /home/customer/www/helpleh.com.sg/public_html/wp-content/plugins plugins_size: 11.82 MB (12389390 bytes) database_size: 2.30 MB (2408448 bytes) total_size: 96.41 MB (101093181 bytes)

wp-active-theme

name: Divi (Divi-4) version: 4.0.9 author: Elegant Themes author_website: http://www.elegantthemes.com parent_theme: none theme_features: custom-background, automatic-feed-links, post-thumbnails, menus, title-tag, post-formats, woocommerce, wc-product-gallery-zoom, wc-product-gallery-lightbox, wc-product-gallery-slider, customize-selective-refresh-widgets, editor-style, widgets theme_path: /home/customer/www/helpleh.com.sg/public_html/wp-content/themes/Divi-4

wp-themes-inactive (4)

Twenty Nineteen: version: 1.4, author: the WordPress team Twenty Seventeen: version: 2.2, author: the WordPress team Twenty Sixteen: version: 2.0, author: the WordPress team Twenty Twenty: version: 1.1, author: the WordPress team

wp-plugins-active (2)

Advanced Custom Fields: version: 5.8.7, author: Elliot Condon Pods - Custom Content Types and Fields: version: 2.7.16.2, author: Pods Framework Team

wp-media

image_editor: WP_Image_Editor_GD imagick_module_version: Not available imagemagick_version: Not available gd_version: bundled (2.1.0 compatible) ghostscript_version: 9.27

wp-server

server_architecture: Linux 3.12.18-clouder0 x86_64 httpd_software: Apache php_version: 7.1.33 64bit php_sapi: cgi-fcgi max_input_variables: 3000 time_limit: 120 memory_limit: 768M max_input_time: 120 upload_max_size: 128M php_post_max_size: 128M curl_version: 7.61.1 OpenSSL/1.1.1d suhosin: false imagick_availability: false htaccess_extra_rules: false

wp-database

extension: mysqli server_version: 5.7.25-28-log client_version: mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $

wp-constants

WP_HOME: undefined WP_SITEURL: undefined WP_CONTENT_DIR: /home/customer/www/helpleh.com.sg/public_html/wp-content WP_PLUGIN_DIR: /home/customer/www/helpleh.com.sg/public_html/wp-content/plugins WP_MAX_MEMORY_LIMIT: 768M WP_DEBUG: false WP_DEBUG_DISPLAY: true WP_DEBUG_LOG: false SCRIPT_DEBUG: false WP_CACHE: false CONCATENATE_SCRIPTS: undefined COMPRESS_SCRIPTS: undefined COMPRESS_CSS: undefined WP_LOCAL_DEV: undefined DB_CHARSET: utf8 DB_COLLATE: undefined

wp-filesystem

wordpress: writable wp-content: writable uploads: writable plugins: writable themes: writable

pods

pods-server-software: Apache pods-user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15 pods-session-save-path: /tmp pods-session-save-path-exists: Yes pods-session-save-path-writable: Yes pods-session-max-lifetime: 1440 pods-opcode-cache-apc: No pods-opcode-cache-memcached: No pods-opcode-cache-opcache: Yes pods-opcode-cache-redis: No pods-object-cache-apc: No pods-object-cache-apcu: No pods-object-cache-memcache: No pods-object-cache-memcached: Yes pods-object-cache-redis: No pods-memory-current-usage: 7.123M pods-memory-current-usage-real: 8.000M pods-network-wide: No pods-install-location: /home/customer/www/helpleh.com.sg/public_html/wp-content/plugins/pods/ pods-developer: No pods-tableless-mode: No pods-light-mode: No pods-strict: No pods-allow-deprecated: Yes pods-api-cache: Yes pods-shortcode-allow-evaluate-tags: No

`

Pods Package Export (helpful!)

{"meta":{"version":"2.7.16.2","build":1578299886},"pods":{"7":{"id":7,"name":"car","label":"Cars","description":"","type":"post_type","storage":"meta","object":"","alias":"","fields":{"make":{"id":8,"name":"make","label":"Make","description":"","help":"","class":"","type":"text","weight":0,"pick_object":"","pick_val":"","sister_id":"","required":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","text_repeatable":0,"text_placeholder":""},"model":{"id":9,"name":"model","label":"Model","description":"","help":"","class":"","type":"text","weight":1,"pick_object":"","pick_val":"","sister_id":"","required":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","text_repeatable":0,"text_placeholder":""},"price":{"id":10,"name":"price","label":"Price","description":"","help":"","class":"","type":"currency","weight":2,"pick_object":"","pick_val":"","sister_id":"","required":"0","currency_format_type":"number","currency_format_sign":"usd","currency_format_placement":"before","currency_format":"i18n","currency_decimals":"2","currency_decimal_handling":"none","currency_step":"1","currency_min":"0","currency_max":"1000","currency_max_length":"12","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","currency_repeatable":0,"currency_placeholder":""}},"show_in_menu":"1","label_singular":"Car","public":"1","show_ui":"1","supports_title":"1","supports_editor":"1","publicly_queryable":"1","exclude_from_search":"0","capability_type":"post","capability_type_custom":"car","capability_type_extra":"1","has_archive":"0","hierarchical":"0","rewrite":"1","rewrite_with_front":"1","rewrite_feeds":"0","rewrite_pages":"1","query_var":"1","can_export":"1","default_status":"draft","supports_author":"0","supports_thumbnail":"0","supports_excerpt":"0","supports_trackbacks":"0","supports_custom_fields":"0","supports_comments":"0","supports_revisions":"0","supports_page_attributes":"0","supports_post_formats":"0","built_in_taxonomies_category":"0","built_in_taxonomies_link_category":"0","built_in_taxonomies_post_tag":"0","built_in_taxonomies_project_category":"0","built_in_taxonomies_project_tag":"0","menu_position":"0","show_in_nav_menus":"1","show_in_admin_bar":"1","pfat_enable":"0","pfat_run_outside_loop":"0","pfat_append_single":"append","pfat_filter_single":"the_content","pfat_append_archive":"append","pfat_filter_archive":"the_content","rest_enable":"0","read_all":"0","write_all":"0"}}}

Additional context

This issue has also been raised in the WordPress support forum

https://wordpress.org/support/topic/custom-field-and-divi-4-template/ https://wordpress.org/support/topic/custom-fields-not-available-in-divi-theme-builder/

And also on the Divi Support Forum

https://www.elegantthemes.com/forum/viewtopic.php?f=187&t=898718

Possible Workaround Use Advanced Custom Fields or Elementor

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label Type: Bug to this issue, with a confidence of 0.88. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

christianmarth commented 4 years ago

Looking at the function in Divi to get custom dynamic content fields in Divi

includes/builder/feature/dynamic-content.php

/**
 * Get custom dynamic content fields.
 *
 * @since 3.17.2
 *
 * @param integer $post_id
 *
 * @return array[]
 */
function et_builder_get_custom_dynamic_content_fields( $post_id ) {
    $raw_custom_fields = get_post_meta( $post_id );
    $raw_custom_fields = is_array( $raw_custom_fields ) ? $raw_custom_fields : array();
    $custom_fields     = array();

    /**
     * Filter post meta accepted as custom field options in dynamic content.
     * Post meta prefixed with `_` is considered hidden from dynamic content options by default
     * due to its nature as "hidden meta keys". This filter allows third parties to
     * circumvent this limitation.
     *
     * @since 3.17.2
     *
     * @param string[] $meta_keys
     * @param integer $post_id
     *
     * @return string[]
     */
    $display_hidden_meta_keys = apply_filters( 'et_builder_dynamic_content_display_hidden_meta_keys', array(), $post_id );

    foreach ( $raw_custom_fields as $key => $values ) {
        if ( substr( $key, 0, 1 ) === '_' && ! in_array( $key, $display_hidden_meta_keys ) ) {
            // Ignore hidden meta keys.
            continue;
        }

        if ( substr( $key, 0, 3 ) === 'et_' ) {
            // Ignore ET meta keys as they are not suitable for dynamic content use.
            continue;
        }

        $label = str_replace( array( '_', '-' ), ' ', $key );
        $label = ucwords( $label );
        $label = trim( $label );

        /**
         * Filter the display label for a custom field.
         *
         * @since 3.17.2
         *
         * @param string $label
         * @param string $meta_key
         */
        $label = apply_filters( 'et_builder_dynamic_content_custom_field_label', $label, $key );

        $field = array(
            'label'    => $label,
            'type'     => 'any',
            'fields'   => array(
                'before' => array(
                    'label'   => esc_html__( 'Before', 'et_builder' ),
                    'type'    => 'text',
                    'default' => '',
                    'show_on' => 'text',
                ),
                'after'  => array(
                    'label'   => esc_html__( 'After', 'et_builder' ),
                    'type'    => 'text',
                    'default' => '',
                    'show_on' => 'text',
                ),
            ),
            'meta_key' => $key,
            'custom'   => true,
            'group'    => __( 'Custom Fields', 'et_builder' ),
        );

        if ( current_user_can( 'unfiltered_html' ) ) {
            $field['fields']['enable_html'] = array(
                'label'   => esc_html__( 'Enable raw HTML', 'et_builder' ),
                'type'    => 'yes_no_button',
                'options' => array(
                    'on'  => esc_html__( 'Yes', 'et_builder' ),
                    'off' => esc_html__( 'No', 'et_builder' ),
                ),
                'default' => 'off',
                'show_on' => 'text',
            );
        }

        $custom_fields[ "custom_meta_{$key}" ] = $field;
    }

    /**
     * Filter available custom field options for dynamic content.
     *
     * @since 3.17.2
     *
     * @param array[] $custom_fields
     * @param int     $post_id
     * @param mixed[] $raw_custom_fields
     *
     * @return array[]
     */
    $custom_fields = apply_filters( 'et_builder_custom_dynamic_content_fields', $custom_fields, $post_id, $raw_custom_fields );

    return $custom_fields;
}

The output of the function get_post_meta($id) where $id is set to a known id of a custom post with custom fields is

The custom fields created with pods are make, model and price

The custom field created with ACF (Advanced Custom Fields) is transmission

[_edit_last] => Array (
    [0] => 1
    )
[_edit_lock] => Array (
    [0] => 1578297290:1
    )
[make] => Array (
    [0] => Daihatsu
    )
[model] => Array (
    [0] => Charade
    )
[price] => Array (
    [0] => 15000.00
    )
[transmission] => Array (
    [0] => Automatic
    )
[_transmission] => Array (
    [0] => field_5e12e7aa9aade
    )

This would lead to me to assume that Divi dynamic content function is not recognising the custom fields stored in post_meta by pods

christianmarth commented 4 years ago

An interesting observation, if I hardcode the $post_id in the et_builder_get_custom_dynamic_content_fields function to my custom post, it will retrieve all the custom fields from Pods and it's functioning as expected

Hardcoding the Post ID in dynamic-content.php L:476 to one that is a known custom-post with custom fields built using Pods

Screen Shot 2020-01-06 at 8 31 54 PM

The post_id of the cars custom post_type item

Screen Shot 2020-01-06 at 8 32 35 PM

The Divi Theme Builder editor showing the custom fields from Pods

Screen Shot 2020-01-06 at 8 31 23 PM

The front end rendering the custom fields from my custom post type built using Pods

Screen Shot 2020-01-06 at 8 40 08 PM
christianmarth commented 4 years ago

Tagging developers of @elegantthemes to review this issue

@lceberg @lots0logs @Moonomo @sofyansitorus @Abd-Ur-Rehman

VladET commented 4 years ago

@christianmarth Thanks for bringing this to our attention!

Currently, the Theme Builder only supports custom fields created with the Advanced Custom Fields plugin but we are working on a fix that will add support for all custom fields that have a stored value regardless of which plugin was used to create them.

I think you can close this here since we'll address it on our end. :smile:

christianmarth commented 4 years ago

@VladET Thank you, When is this expected to be resolved and is there a patch that can be used in the meantime?

JoryHogeveen commented 4 years ago

Closing this topic here! @VladET Thank you for the update.

VladET commented 4 years ago

@christianmarth We are still working on this so we don't have a patch I'm afraid and I also don't have an ETA I can share at the moment.

@JoryHogeveen You're welcome! :smile:

Deliciae commented 4 years ago

Not to hijack this thread but i'm using ACF and the custom fields aren't being displayed either. @VladET

VladET commented 4 years ago

@Deliciae ACF custom fields are supported right now in Divi. Please open a chat with our Support Team on https://www.elegantthemes.com/ and we will be happy to take a closer look.

I would also like to point out that this is the Pods Framework repo which is owned by a different company. The best way to reach out to us, Elegant Themes, in regard to any of our products is by opening a chat through our main website.

fwolfst commented 4 years ago

I'd be happy if somebody posts an update here if the issue is solved on divi side.

Cowbelly commented 4 years ago

Status update on PODs custom fields and Divi Theme Builder?

jimtrue commented 4 years ago

@Cowbelly Please read the thread of the conversation above. This is an issue that needs to be handled by Elegant Themes (https://github.com/pods-framework/pods/issues/5565#issuecomment-571199559). You folks would need to open a ticket with them and they'll link it to the issue on their side.

ChAsadUrRehman commented 4 years ago

here is a simple fix (temporary because you will need to perform these steps after each Divi update) that you guys can use until Divi Devs get some time to fix this simple issue https://github.com/ChAsadUrRehman/show-custom-fields-in-divi-dynamic-content-field

jhit commented 4 years ago

@ChAsadUrRehman I tried your patch and it did not work. I still get no custom fields for my posts in the Divi Theme Editor.

ChAsadUrRehman commented 4 years ago

@jhit I just tested and it's working perfectly fine (Screenshot Attached)... maybe if you can share your dynamic-content.php and I will be happy to have a look and help you debugging and fixing the issue :-)

image

jhit commented 4 years ago

@christianmarth https://gist.github.com/jhit/2a21689f5a138c6487f9b02ebeb2af2f Thank you for your help.

ChAsadUrRehman commented 4 years ago

@jhit I copy pasted your code and it's working fine. Maybe if you can test this on your another test/staging site?

baba43 commented 4 years ago

@VladET is there any issue / link we can follow to see a status of this?

Or are you willing to keep this thread updated, since everyone is arriving here right now.

jimtrue commented 4 years ago

@baba43 They only keep coming here because our GitHub is public. This issue needs to be addressed at the Divi side of the equation :)

baba43 commented 4 years ago

@jimtrue I know, that's why I tagged VladET, or is that wrong?

VladET commented 4 years ago

@baba43 @jimtrue We've addressed this in Divi 4.4.4 which was released just a few days ago.

version 4.4.4 ( updated 04-23-2020 )
- Added input field to enter the meta_key in the Dynamic Content field option list.
[...]

In addition to this, we are also now displaying a list of 50 most used registered custom fields. The limit is in place for performance reasons.

In the following screenshots, you'll see I have a Cars custom post type with 3 custom fields (Make, Model, and Year) and these custom fields are now displayed in the dynamic content custom fields list.

If you have a lot of custom fields and the one you need is not on the list, you can use the Manual Custom Field Name filed to add it.

image