Support » Plugins » Creating a new post without using admin.php

  • crisispictures


    I’m having trouble using the wpdb class for this utility i created to automatically post iptc images.

    what it does successfully is:

    1. extracts a zip file full of images.
    2. extracts the iptc data.
    3. takes the country field from one of the images and uses that as the category.
    4. takes the headline field and uses that as post title.
    5. puts all of the images into the content followed by the IPTC caption.
    6. put all that in a form so i can double-check everything.

    7. Posts to my blog.


    I cribbed the wpdb stuff from the import-rss.php file in wp-admin. so i don’t really understand what’s going on when it posts.

    it posts, but it doesn’t put dash’s in the blank spaces in the post-slug, so the permalink is screwed up.

    i’d like it to post to custom fields and theexcerpt as well, but I can’t find info on how to set that up.


    I’d like to release this as a plugin/extension, but I don’t know what the best way to secure it is. How do I
    check to see that the admin has logged in?

    This is the query that I’m using:

    $wpdb->query("INSERT INTO $wpdb->posts
    (post_author, post_date, post_date_gmt, post_content, post_title,post_status, comment_status, ping_status, post_name, guid)
    ('$post_author', '$post_date', DATE_ADD('$post_date', INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE), '$content', '$title', 'publish', '$comment_status', '$ping_status', '$post_name', '$guid')");
    $post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$title' AND post_date = '$post_date'");
    if (!$post_id) die("couldn't get post ID");
    if (0 != count($categories)) :
    foreach ($categories as $post_category) :
    $post_category = unhtmlentities($post_category);
    // See if the category exists yet
    $cat_id = $wpdb->get_var("SELECT cat_ID from $wpdb->categories WHERE cat_name = '$post_category'");
    if (!$cat_id && '' != trim($post_category)) {
    $cat_nicename = sanitize_title($post_category);
    $wpdb->query("INSERT INTO $wpdb->categories (cat_name, category_nicename) VALUES ('$post_category', '$cat_nicename')");
    $cat_id = $wpdb->get_var("SELECT cat_ID from $wpdb->categories WHERE cat_name = '$post_category'");
    if ('' == trim($post_category)) $cat_id = 1;
    // Double check it's not there already
    $exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_id AND category_id = $cat_id");

    if (!$exists) {
    INSERT INTO $wpdb->post2cat
    (post_id, category_id)
    ($post_id, $cat_id)

Viewing 2 replies - 1 through 2 (of 2 total)
  • skippy



    Writing_A_Plugin is probably the best place to start, if you’re new to writing plugins.

    Explaining the post processing logic is awkward, and time consuming. You’re likely better off reading post.php to see what sequence of events occur when you normally press “Publish”.




    so i know what i’m looking for:

    What part of the query crates the post-slug, custom metatags excerpt fields?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Creating a new post without using admin.php’ is closed to new replies.