• valchy

    (@valchy)


    Hello.
    I have downloaded an image from an outside website url and I want to add it to a specific post.
    How can I do this (I mean how can I write the code)?
    I try some php but it doesn’t show me the image sizes, so I need some short example on how to add the image to a post and how to add the data for the image in the wp-posts and wp-postmeta.
    The url to the image is something like this:
    localhost/wp-contents/upload/year/month/image_title.php
    What exactly I need is to create the data from wp-postmeta.

    Thanks in advance

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator t-p

    (@t-p)

    in Admin – Psts

    look for “Upload/Insert” above the visual edotor

    Thread Starter valchy

    (@valchy)

    i know that. I need a small code to create image metadata. Something like:

    include file.php
    metadata (var1,var2,var3);

    esmi

    (@esmi)

    Perhaps custom fields?

    Thread Starter valchy

    (@valchy)

    I try to write a php code to create posts from outside wordpress admin panel, so I need to add an image to the media library. I keep trying to figure out how but I haven’t managed to find something that I want.
    I’m trying something like this:
    1. download the image from the source website (curl) – done.
    now, the image is on the folder “wp-content/2012/07/” and the name of the image is image.jpg.
    2. what I need now is the php code to enter this image in the media library so it can be seen from the admin panel.
    i know i need to create an array with the image data and insert it into the database but I don’t know how. I’m not an expert in php …

    Thread Starter valchy

    (@valchy)

    I wrote some code:

    include "wp-includes/plugin.php";
    include "wp-admin/includes/media.php";
    include "wp-admin/includes/file.php";
    $file = "http://image_address/Rock_of_Ages_2012.jpg";
    $post_id = 1;
    $desc = "testare upload";
    media_sideload_image($file, $post_id, $desc);

    but I get this error:

    Fatal error: Call to undefined function __() in C:\xampp\htdocs\wp-admin\includes\file.php on line 11

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to add image to a post’ is closed to new replies.