• Resolved a951a581

    (@a951a581)


    Hi David,

    Very useful plugin!

    I am trying to set the External Featured Image using the XML-RPC WordPress API. To figure out how to do this, I manually set the External Featured Image from the edit post GUI. Then I request all post info for trough the API with wp.getPost but I don’t find anything related to your External Featured Image plugin in the returned data, even though the post successfully displays the External Featured Image. The returned data contains the post’s custom fields, but nothing related to External Featured Image. So it seems the External Featured Image is not set using a custom field, even though this topic says it is.

    I think this question is related but I still couldn’t figure it out.

    Could you explain how to set the External Featured Image using the API?

    Thanks in advance ??

    https://www.ads-software.com/plugins/external-featured-image/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author David Aguilera

    (@davilera)

    Hi! We do use a custom field named _nelioefi_url. Now, do you see the first underscore? That means that the custom field is “private”, and therefore it should not be shown in the Custom Fields metabox. I’m no expert on the API you mention, but is it possible that private custom fields are not returned?

    Thread Starter a951a581

    (@a951a581)

    Hi David thanks for the reply and explanation. I didn’t know that custom fields starting with an underscore are special. I think your right, these private custom fields are the reason the API doesn’t return them. I couldn’t find a good explanation on how to update these hidden custom fields through the XML-RPC API. The most promising post seems to be this one because he’s talking about “Using custom_fields with meta_id”. Does the explanation make sense to you?

    The only option I can think of right now is to modify your plugin and remove the underscores. That should be fairly straight forward and solve my problem, don’t you think?

    Thanks again ??

    Plugin Author David Aguilera

    (@davilera)

    Yes. The easiest solution is to remove the underscore. In fact, you don’t need to edit our plugin at all. Just add the following piece of code in your theme’s functions.php file:

    add_filter( 'nelioefi_post_meta_key', 'nelio_remove_underscore' );
    function nelio_remove_underscore( $meta_name ) {
      return 'nelioefi_url';
    }

    And that’s it! From now on, the meta_name our plugin uses will be nelioefi_url. What’s great about this solution is that there’s no need to modify the plugin after you update it with a new release (that’s why we added the filter in the first place).

    That said, using “regular” (instead of “internal”) metas might cause some trouble, for you can edit them directly using WordPress built-in meta editors… but I’m sure you’ll be careful!

    Best,

    Thread Starter a951a581

    (@a951a581)

    Thanks for your reply David!

    I removed the underscores and it’s working out great. I had to change a few things in the plugin anyway to make it work in my theme, such as using a 2×3 pixel gif to change the aspect ratio of the thumbnails.

    $html = sprintf(
    			//'<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" ' .
    			// use a 2x3 image to define the poster aspect ratio
    			'<img src="data:image/gif;base64,R0lGODlhAgADAIAAAP///wAAACH5BAEAAAAALAAAAAACAAMAAAIChF8AOw==" ' .
    			'style="background:url(\'%s\') no-repeat center center;' .
    			'-webkit-background-size:cover;' .
    			'-moz-background-size:cover;' .
    			'-o-background-size:cover;' .
    			'background-size:cover;' .
    			'%s%s" class="%s wp-post-image nelioefi" '.
    			'alt="%s" />',
    			//$image_url, $width, $height, $additional_classes, $alt );
    			// ignore the image width and height, the theme css will take care of that
    			$image_url, 0, 0, $additional_classes, $alt );

    These modifications can’t be done in the theme’s functions.php file I suppose, right? Anyway wouldn’t that just move the problem? If the plugin is updated, my modification would still be in the theme’s functions.php file. But if the theme is updated, then my modifications are still lost, right?

    Reason for asking is that I’m modifying a lot of php files lately and I am sure I’m going to run into problems with updating! Just trying to figure out where would be the best place for my modifications.

    Thanks again, really cool plugin.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using XML-RPC WordPress API to set External Featured Image’ is closed to new replies.