Support » Plugins and Hacks » Be nice and help a newbie with php/mysql

  • Resolved 3stripe

    (@3stripe)


    Hello folks,

    I’m using WordPress to update a Flash news feed. The mySQL post data is fed directly into Flash via a simple php file.

    It was working fine, until I added images to the mix, using the “Meta Image” plugin…(http://no.oneslistening.com/151)

    Now it seems that images which don’t have a meta image don’t show up in my list of articles.

    So at http://www.thirdeyedesign.co.uk/news/wptest3.html you can’t see the third story, because it doesn’t have an image.

    So, if anyone could help me tweak my code so that posts without an image show up, I would be very very grateful!

    mysql_select_db ("wordpress");
    $qResult = mysql_query ("SELECT * FROM wp_posts, wp_post2cat, wp_postmeta, wp_categories WHERE wp_posts.ID=wp_post2cat.post_id AND wp_post2cat.post_id=wp_postmeta.post_id AND wp_posts.post_status='publish' AND wp_post2cat.category_id=wp_categories.cat_ID AND wp_categories.cat_name='$category' ORDER BY ID DESC");

Viewing 7 replies - 1 through 7 (of 7 total)
  • Ps. I have tried removing ‘wp_post2cat.post_id=wp_postmeta.post_id’ – but when I do this, I get multiple instances of each story appearing in the list of headlines – so it seems to mess something up.

    Try this, it’ll return posts regardless of wether or not there are any corresponding wp_postmeta records:


    $qResult = mysql_query ("SELECT * FROM wp_posts LEFT JOIN wp_postmeta ON (wp_posts.ID=wp_postmeta.post_id), wp_post2cat , wp_categories WHERE wp_posts.ID=wp_post2cat.post_id AND wp_posts.post_status='publish' AND wp_post2cat.category_id=wp_categories.cat_ID AND wp_categories.cat_name='technical' ORDER BY ID DESC");

    Hey wow thank you so much 🙂

    Worked first time!

    Could you explain the difference in that code then… how does JOIN work?

    SELECT * FROM tableA LEFT JOIN tableB ON (tableA.c1 = tableB.ac1) means:

    Give me EVERY row from tableA; and where tableA.c1 does not have a matching tableB.ac1, just slap a null value for tableB.ac1 in the result and call it a day.

    Ok that makes sense, cheers for the info!

    This is working great now for me, but I wonder is it possible to change the output result so that it lists the posts by date, with newest at the top?

    I’m guessing it would be “ORDER BY post_date DESC”??

    [update: yup!]

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Be nice and help a newbie with php/mysql’ is closed to new replies.