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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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