Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8934749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:51:24+00:00 2026-06-15T09:51:24+00:00

Please can you guys help me check if my syntax is correct. I don’t

  • 0

Please can you guys help me check if my syntax is correct. I don’t get any errors using this code but I just wanted few opinions on whether I’m doing it right or not.

I’m using a multi-site WordPress installation and I’m checking to see if the featured blog is older than a day but less than a week old:

/* Work out blog of the day */
$featured_id = get_option('featured_blog'); # Current ID
$featured_time = get_option('featured_time'); # Current Time

if($featured_time > time()-86400 && $featured_time < time()-604800) // more than 1 Day ago but less than a week
{
    $query = "SELECT blog_id FROM `wp_blogs` WHERE public = '1' and archived = '0' and spam = '0' and deleted = '0' AND blog_id NOT IN ('".$featured_id."', '1','27') ORDER BY rand() limit 1";
    $featured_id = $wpdb->get_var($query);
    update_option('featured_blog', $featured_id);
    update_option('featured_time', time());
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:51:25+00:00Added an answer on June 15, 2026 at 9:51 am

    According to http://codex.wordpress.org/Database_Description#Table:_wp_blogs, the column blog_id is int, so you should not enclose the values in quotes

    select ... where ... and blog_id NOT IN (".$featured_id.", 1,27) ...
    

    Same for columns public, spam and deleted.

    Besides that, which isn’t a real problem, I can’t spot any syntax error.
    But contrary to your title, you don’t use the time in your query.

    To the if() statement, this will never become true, because $featured_time cannot be > now - 86400 and < now-604800 at the same time. If you want the condition as in your comment, say

    if ($featured_time < time()-86400 && $featured_time > time()-604800)
    

    On a time()-line this looks more or less like this

    0          now-604800   now-86400      1354618129
    +----------+------------+--------------+
    |          |            |              |
    1.1.1970   a week ago   24 hours ago   now
    

    So, if $featured_time should be between a week ago and a day ago, it must be greater than a week ago (> now – 604800) and less than a day ago (< now – 86400).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you guys please check this code, it is MVC3 Razor <p><strong><u>Skills:</u></strong> @foreach (var
Can you guys please help me with this jsFiddle?: http://jsfiddle.net/4CNKa/2/ I am trying to
Can you guys please help me in this matter : I have two variable
Can you guys help with this please? I need to convert a real number,
Please can someone help? I have the following code which uploads a file to
Can someone please help me with this preg_match if (preg_match('~[^A-Za-z0-9_\./\]~', $filepath)) // Show Error
Hope you guys can help me. This is my situation. I have a stored
Hi guys please could you help do this I tried to read about jquery,
I'm new at using this. Help me please. I am really confused. Please help
How to delete from database result of this query? can you guys help me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.