Support » Plugin: Meta Box - WordPress Custom Fields Framework » Fields data doesn’t appear on frontend

  • giggioman00

    (@giggioman00)


    I have a problem while importing posts from a csv with custom fields made with this plugin

    Basically, the data in the custom fields is correctly imported into the database, but the data doesn’t appear on the fronted of my posts.

    I noticed that if I manually open the post and click “Update”, without changing anything inside the imported posts, then the fields data appears correctly in the frontend. The bulk edit doesn’t work though, it works only if I manually open and update each post.

    After investigating in the database I noticed that under manually saved posts, a weird string seems to wrap my data in the Metabox custom fields. This kind of wrapping code is like this:

    a:1:{i:0;s:224:"MY DATA";}

    This string appears in the posts manually saved (which data appears correctly in the fronted) but it doesn’t appear under imported posts (which data doesn’t appear in the frontend).

    The problem is, if I try to add this kind of wrapping code in the csv file that I import, it doesn’t work. This code is added inside the custom field and the frontend is still empty.

    I have no idea if this is the reason for the fields not appearing on fronted when imported.
    But I need your helping on figure this out. I need to import a hunge amount of posts with custom data (more than 10k posts) so I can’t manually update each post one by one.

    Please give me a solution to let these data appears on the frontend, I don’t care if you recommend me a plugin that mass updates all posts by adding these strings(tried a bunch of them with no success) or if you give me a solution to make the data appear directly in the frontend, I would just like a solution to this problem, thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Long Nguyen

    (@longnguyen)

    Hi,

    Thank you for reaching out.

    Can you please share the code that creates the custom fields, the file import, and let me know how did you import the data? I will try to reproduce the issue on my end.

    If it’s private data, please share it via this contact form https://metabox.io/contact/.

    Thread Starter giggioman00

    (@giggioman00)

    Hello, sadly I can’t share the code that creates the custom fields, because I’m not a developer. There is a premium theme that I bought that simply use your plugin, I asked them if they could give me the code but they refused because that part it’s encrypted. They told me though, that they 100% followed your documentation and they didn’t anything weird.

    I have imported the data with this plugin: https://wordpress.org/plugins/wp-ultimate-csv-importer/
    I didn’t anything weird while importing because while importing this plugin automatically detect and map all the custom fields.

    For the file that I import, actually it is a csv file. Don’t know how I can attach this file here so for the moment I attach you a screenshot: https://imgur.com/a/HXJrxP7
    (Yes I’m getting this problem with the ‘ero_embed’ field which is a video embed script… the script it’s imported in the database but it doesn’t show in the frontend until I manually open and save the post)

    Thank you

    Plugin Support Long Nguyen

    (@longnguyen)

    Hi,

    I’m not sure about the field type and the code outputs the field value that the theme is using. If the field value is the HTML code, you can ask them to use the field type WYSIWYG. See more on the documentation https://docs.metabox.io/fields/wysiwyg/

    Thread Starter giggioman00

    (@giggioman00)

    Sorry, my bad. The arrays are encrypted but I can change the type of the fields.
    I tried to change the type of the field from textarea to wysiwyg but it doesn’t work. Same problem, the HTML code is there but it doesn’t appear on the frontend until I save the post.
    I attach that part of the script, it’s the only piece of code I have access

    $meta_boxes[] = array(
            'title'  => 'Embed Video',
    		'pages' => array( 'post' ),
    		'tabs'      => array(
                'input-version' => array(
                    'label' => 'Input Version',
                    'icon'  => 'dashicons-admin-customizer',
                ),
                'sc-version'  => array(
                    'label' => 'Shortcode Version',
                    'icon'  => 'dashicons-editor-code',
                ),
            ),
    		'tab_style' => 'default',
            'fields' => array(
                array(
                    'id'     => 'ab_embedgroup',
                    'type'   => 'group',
                    'clone'  => true,
    				'sort_clone'  => true,
    				'save_state' => true,
    				'desc' => '<b style="color:red;">You can insert embed code or shortcode</b>',
    				'tab'  => 'input-version',
                    'fields' => array(
                        array(
                            'name'  => 'Host Name',
                            'id'    => 'ab_hostname',
                            'type'  => 'text',
                        ),
                        array(
                            'name'   => 'Embed',
                            'id'     => 'ab_embed',
                            'type'   => 'wysiwyg',
    						'sanitize_callback' => 'none',
                        ),
                    ), 
                ), //input-version
    			array(
                    'name'  => __( 'Shortcode Video', 'meta-box' ),
                    'id'    => "ero_embed",
                    'type'  => 'wysiwyg',
    				'clone' => true,
    				'sort_clone'  => true,
    				'sanitize_callback' => 'none',
    				'tab' => 'sc-version',
                ),
            ),
        );

    Any idea what else we can try?

    Plugin Support Long Nguyen

    (@longnguyen)

    Hi,

    I think there are two points that cause the issue.

    1. The cloneable field, the value of cloneable field saved in the database is a serialized array, like this

    a:2:{i:0;s:246:"<p><video controls="controls" width="250" height="150"><source src="/media/cc0-videos/flower.webm" type="video/webm" /><source src="/media/cc0-videos/flower.mp4" type="video/mp4" />Sorry, your browser doesn't support embedded videos.</video></p>
    ";i:1;s:246:"<p><video controls="controls" width="250" height="150"><source src="/media/cc0-videos/flower.webm" type="video/webm" /><source src="/media/cc0-videos/flower.mp4" type="video/mp4" />Sorry, your browser doesn't support embedded videos.</video></p>
    ";}

    So if you import only HTML tag, it might not work.

    2. The tag <source> is not an allowed HTML tag and does not pass the sanitize callback function of the WYSIWYG field wp_kses_post. You can bypass the sanitization by following the documentation https://docs.metabox.io/sanitization/#bypass-the-sanitization.

    Thread Starter giggioman00

    (@giggioman00)

    Hello, thank you very much for your answer.
    I tried to set the cloneable field to false, but apparently doesn’t work, the problem is still there. But I do think this is the main issue… when imported, the HTML code it’s there in the field but it’s not serialized. And it doesn’t appear on the frontpage this way. But when I open the post and save the post, then the HTML code becomes serialized and do appear on the frontpage.

    For the second option, the sanitize_callback is already set to none in the custom fields. Do I need to change something in the wp_kses_post file? I think I didn’t get that

    Plugin Support Long Nguyen

    (@longnguyen)

    Ok, so you can try to get the field value in the database after saving a post like your first comment a:1:{i:0;s:224:"MY DATA";} or my previous comment and re-import it to another post. The cloneable field does not accept only the HTML code, it should be in a serialized array.

    Sanitize callback is ok, you don’t need to change anything else.

    Thread Starter giggioman00

    (@giggioman00)

    I can’t manually save the posts because I need to import 10k posts, it’s too much to save 10k posts manually.

    I can’t import the same serialized array in all the posts because in each post the source URL change, so a different number of characters is used in the HTML code and so the serialized array change every time, if you import the same serialized array it simply doesn’t work.

    Please suggest me a proper solution?
    Is there a way to remove the serialized generation from your script, or do you know a plugin that can help me? Or maybe other solution? Thank you

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Fields data doesn’t appear on frontend’ is closed to new replies.