• Hello,
    in a theme that I service, a custom post is created with Magic Fields 2. I has Image Media type of custom field. And it does not work.
    I click “set image” button, I choose the image I want and I click “Insert into post” button as there is no other button. Hence – no image in my custom post…
    I would be grateful for your help.

    https://www.ads-software.com/plugins/magic-fields-2/

Viewing 11 replies - 1 through 11 (of 11 total)
  • The button label “Insert into post” is somewhat misleading. It actually just does an insert into a Magic field. You still need to display the Magic field itself.

    mc

    This is the exact issue I am having: Custom Post Type -> Image Media Custom Field, “insert into post”

    When I do this, I get a “broken image” thumbnail in my meta field, not a nice thumbnail.

    MagicFields2 2.3.1 and WP v. 4.3-alpha (pulled from the .git repo)

    array(2) { [1]=> array(2) { [“original”]=> NULL [“thumb”]=> NULL } [2]=> array(2) { [“original”]=> NULL [“thumb”]=> NULL } }

    This is the var_dump() of the get_field() of my Image Media field. “original” and “thumb” are both NULL

    Forget it. Evidently this plugin isn’t being maintained anymore. I’ve wasted an entire day trying to figure this out. I’m switching to Advanced Custom Fields. Much more stable. Much more user friendly.

    I am not the author of this plugin, however I do try to support it. (I have a selfish reason for doing so as this plugin is a prerequisite for my plugin.) I know that the Image Media field is working on Magic Fields 2.3.1 with WordPress 4.2.2 (at least it is working in my environment). Your var_dump() indicates the field may not exists or has no attached images. I would try a SELECT * from wp_postmeta WHERE meta_key = “your field name” AND post_id = “post id of the post containing the image”. This row must exists for get() or get_field() or get_image() to work. If this row exists then check that the meta_value is the id of an attachment and the attachment has images.

    Turns out, Magic Fields2 and ACF are incompatible in the same environment, as they both declare a “get_field()” function, which cancel each other out, so you get a fatal error. Should’ve started with ACF to begin with.

    At any rate, I’ll try your suggestion. But, to be sure, the field *does* exist. I have started over with MF2 — reinstalled the database from a backup I made before starting all this. I’ve also reverted my WP install from the 4.3-Alpha I was using yesterday to the “stable” 4.2.2, deactivated all plugins but MF2, recreated my custom post type, recreated a repeating Image Media field, attempted to add an image from WP Media and … nothing. I still get the “broken image” placeholder in the meta area rather than a nice thumbnail.

    Would you be able to elaborate on the “SELECT *” suggestion you provided above? Thanks.

    Thank-you so much for responding. I think this is a serious problem with MF2 since there has been multiple reports of problems with “Image Media” for the past several months. Unfortunately, I have not been able to duplicate the problem on my system but the problem is very real since several other users have reported it. Your current environment just MF2 and WP 4.2.2 matches mine. But, there must be something – my browser is Firefox 8.0.5 and my user OS is Windows7. Since, your var_dump() shows an array with 2 elements I think the rows were created in the database but they are empty. Creating an “Image Media” element results in two rows being created in MySQL.

    mysql> select * from wp_postmeta where meta_key = "image2" and post_id = 39;
    +---------+---------+----------+------------+
    | meta_id | post_id | meta_key | meta_value |
    +---------+---------+----------+------------+
    |   27897 |      39 | image2   | 541        |
    +---------+---------+----------+------------+
    1 row in set (0.00 sec)
    
    mysql> select * from wp_mf_post_meta where meta_id = 27897;
    +---------+------------+-------------+-------------+---------+
    | meta_id | field_name | field_count | group_count | post_id |
    +---------+------------+-------------+-------------+---------+
    |   27897 | image2     |           1 |           1 |      39 |
    +---------+------------+-------------+-------------+---------+
    1 row in set (0.01 sec)

    Here image2 is an “Image Media” magic field.
    The meta_value should be the id of an post_attachment.

    mysql> select id,post_title,post_type,guid from wp_posts where id = 541;
    +-----+------------+------------+-----------------------------------------------------------------+
    | id  | post_title | post_type  | guid                                                            |
    +-----+------------+------------+-----------------------------------------------------------------+
    | 541 | carter-tq  | attachment | https://me.local.com/wp/wp-content/uploads/2013/03/carter-tq.jpg |
    +-----+------------+------------+-----------------------------------------------------------------+
    1 row in set (0.00 sec)

    Can you check if these rows exists and have valid data.

    As far as I know there is no API for re-using the Media Library’s “Insert Media” functionality and what MF (and others) uses is a JavaScript hack to use “Insert Media” for their own purpose. Can you check the JavaScript console for an error message when you do an “Insert Media”

    Thanks again for your feedback – I have been trying to get a handle on this problem for months.

    I stated that “As far as I know there is no API for re-using the Media Library’s Insert Media” – I just looked at some of my own code that uses Media Library’s “Insert Media” functionality and this is NOT true – there is an API. However, if I remember correctly MF2 uses an earlier JavaScript hack and maybe this has stopped working under some conditions. Only a surmise at this point.

    I have read the Magic Fields 2 JavaScript code that handles the WordPress Media Library Insert Media (which you use when you click on the “Set Image” button of Image Media). In file “…/wp-content/plugins/magic-fields-2/js/mf_admin.js” at line 270 the function mf_use_new_image_gallery() replaces the Media Library wp.media.editor.send.attachment handler with its own handler.

    function mf_use_new_image_gallery(){
    
      if (typeof wp === 'undefined' || typeof wp.media === 'undefined') return; 
    
      var _custom_media = true;
      _orig_send_attachment = wp.media.editor.send.attachment;
    
      jQuery('.update_field_media_upload').removeClass('thickbox');
      jQuery(document).on('click', '.update_field_media_upload',function(e){
        window.mf_field_id = jQuery(this).attr('id').replace('thumb_', '');
        _custom_media = true;
    
        wp.media.editor.send.attachment = function(props, attachment){
          if ( _custom_media ) {
            jQuery("#"+window.mf_field_id).val(attachment.url);
            console.log("mf_use_new_image_gallery():attachment=",attachment.filename);
            mf_set_image_field(attachment.id);
          }else{
            return _orig_send_attachment.apply( this, [props, attachment] );
          };
        }
    
        wp.media.editor.open(jQuery(this));
        return false;
      });

    The function mf_set_image_field() is setting the value for the image. I have inserted a debug console.log() statement above it. If you can do this it should print out the image file name to the console. I am sorry I don’t know how skilled you are at JavaScript debugging.

    Hi Magenta Cuda,
    Thanks for your detailed work! I had to switch to another project for the past day or so but still have this issue. Going to be busy on the other project for the rest of the week but I definitely need to find a solution to my issue. I’ll look over your suggestions in detail this weekend and get back to you with what I came up with. Thanks again for following up on this …

    I was reading some of the earlier reports of this bug and think a possibility is that the wp.media.editor.send.attachment handler is not getting overridden because an earlier JavaScript error prevents the mf_use_new_image_gallery() code from executing. The first thing I would do is confirm that the new handler from Magic Fields 2 is getting installed.

    I also work on the weekend (Actually I don’t really work, I am retired so this is my hobby.) so if you need anything feel free to post something here. Unfortunately, our time zones seem to completely out of sync so it may take a day for you to get my response.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Images are not loading properly wp4.1’ is closed to new replies.