0

I have a little Windows application that I would like to be able to use featured images from posts on my site with.

My site lists and reviews modifications for a computer game and the application installs those modifications. Think of it as a very basic Steam, for those that know what Steam is.

When a user installs a modification from a file on my site, I would like the application to visit the site, search for the file and then use the featured image within the application.

I understand most of that is outside the scope of this thread, but is there a way to find the URL of the image using PHP but outside of WordPress?

Perhaps from the post ID.

1

The most common way to achieve those features is to implement some sort of interface, usually in JSON or XML.

To do this, you either use a plugin (http://wordpress.org/plugins/json-rest-api/ <= Will probably part of core in WP 4.0) or do the AJAX function yourself.

An example would be:

add_action( 'wp_ajax_get_thumbnail', 'ajax_get_thumbnail' );
add_action( 'wp_ajax_nopriv_get_thumbnail', 'ajax_get_thumbnail' );
function ajax_get_thumbnail() {
    $post_id = $_GET['post_id'];
    $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'post-thumbnail' );

    echo json_encode($thumb);

    die(); // this is required to return a proper result
}

The call for that action would be: http://www.yourwebhost.com/wp-admin/admin-ajax.php?action=get_thumbnail&post_id=15

Please mind, that the 15 is just an example. You would get a json object in return, that contains witdh, height and the url to the post thumbnail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.