Jump to content

Need help with php


gsa700

Recommended Posts

Hi all, I am new here and hoping I am posting this in the right place. I am using wordpress as a front end to mySQL to add news items to a database and then using PHP to grab them from the db and include them in a php page. The problem I am having is that I am very basic in my php and adding the db into the equation is more than I can grasp here.

 

So what I need is this: the following code works very well with one exception, it includes ALL posts even if they are no yet published. There is a "post_status" available which is either: "publish" or "draft". I basically want to have my code check to make sure that "post_status" = "publish" before it adds it to the page.

 

Here is my existing code:

( for some reason I couldn't include the code itself so here is a picture of the code )

 

code.png

 

Any help here would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/94209-need-help-with-php/
Share on other sites

change this line:

 

$query.=" FROM wp_posts ORDER BY id DESC LIMIT 3";

 

to

 

$query.=" FROM wp_posts WHERE post_status='publish' ORDER BY id DESC LIMIT 3";

 

I knew it was something simple. ;-)

 

Thank you very much! I did not expect such a fast reply.

 

You guys rock.

Link to comment
https://forums.phpfreaks.com/topic/94209-need-help-with-php/#findComment-482593
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.