WordPress.org

Ready to get started?Download WordPress

Forums

How to add image to a post (6 posts)

  1. valchy
    Member
    Posted 2 years ago #

    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

  2. Tara
    Member
    Posted 2 years ago #

    in Admin - Psts

    look for "Upload/Insert" above the visual edotor

  3. valchy
    Member
    Posted 2 years ago #

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

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

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    Perhaps custom fields?

  5. valchy
    Member
    Posted 1 year ago #

    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 ...

  6. valchy
    Member
    Posted 1 year ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic