Support » Fixing WordPress » Why is the value of this variable changing?

  • Resolved ryanoz

    (@ryanoz)


    the PHP:

    <?php
    $post = $posts[0]; // Hack
    $likedate = 'Y-m-d ';
    
    $count = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_date LIKE '" . get_the_time($likedate) . "%' AND post_date_gmt < '" . current_time('mysql', TRUE) . "' AND post_status = 'publish'");
    echo $count;
    ?>

    the above PHP is in my sidebar.php
    here the value of $count is 3:
    http://www.oswaldtrading.com/testing/

    here the value of $count is 1:
    http://oswaldtrading.com/testing/category-index/

    you can see it echoed on the pages.
    Why is it changing from 3 to 1 ?

    Thanks for looking.

Viewing 15 replies - 1 through 15 (of 20 total)
  • Echo the query. They must be different.

    get_the_time() returns the timestamp of the “current post”.

    I can only guess but the first page looks like a “Page” page, so the time “category-index” page published is used. If no other post/page is published on the same day, only the page itself will be counted. $count = 1.

    In the second page, $post will be the last post called in the loop(titled “eruditi sed in…”). Obviously there are 3 posts published on the same date. $count = 3.

    yea “category-index” is the empty PAGE I published in order to create a category index. Why is the published PAGE counted as POST?

    I don’t want the 3 entries under “previously” to change. How do I keep the query the same?

    This is what’s in my sidebar:

    <?php
    $post = $posts[0]; // Hack
    $likedate = 'Y-m-d ';
    
    $count = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_date LIKE '" . get_the_time($likedate) . "%' AND post_date_gmt < '" . current_time('mysql', TRUE) . "' AND post_status = 'publish'");
    echo $count;
    ?>
    <?php query_posts("showposts=3&offset=$count"); ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?><br /><span><?php the_time('F jS, Y') ?> - <?php wp_link_pages(); ?> <?php comments_number(__('<strong>0</strong> Comments'), __('<strong>1</strong> Comment'), __('<strong>%</strong> Comments')); ?></span></a></li>
    <?php endwhile; else: ?>
    <?php endif; ?>

    Thanks

    Why is the published PAGE counted as POST?

    Pages are stored in the posts table too. They have timestamps and everything else. So do drafts and attachments, for that matter.

    A Page is just a Post with special features. It has a fixed base URL and the option to have it’s own template, but basically it’s the same sort of thing.

    If you only want Posts, you need to add “AND post_type=’post'” to your where clause.

    And yes, get_the_time() is going to return the Page’s timestamp as well. Pages are run through the Loop like everything else is.

    1. You don’t need a “category-index” to list posts in a catgeory. Category Templates just do that for you out of the box.
    2. Your code is wrong for the 2.1 branch. I have found this: http://wordpress.org/support/topic/102028

    otto-

    If you only want Posts, you need to add “AND post_type=’post'” to your where clause.

    Ok, I added that.
    If you look at: http://oswaldtrading.com/testing/category-index/
    you’ll notice in the sidebar “previously” the $count echo
    is showing 0 now because their are no post ON THAT PAGE.
    But I want the the entries under “previously” to be the
    same 3 as on the index page. How do I do that?

    rudolf45

    1. You don’t need a “category-index” to list posts in a catgeory. Category Templates just do that for you out of the box.

    I just wanted to list the categories, not their posts.

    Try something for me:
    echo get_the_time($likedate);

    What’s the date you get for the Page vs. the date you get for the posts?

    Otto-

    Try something for me:
    echo get_the_time($likedate);

    Ok. On my index page it echo’s: 2007-04-24
    On the category-index it echo’s: 2007-04-25

    You can see it on the two links i’ve listed above.
    The first number echo’d is the value of $count.

    Well, there you go then. Look at your query:

    SELECT COUNT(ID) FROM $wpdb->posts WHERE post_date LIKE '2007-04-25%'...

    Do you *have* any posts made on the 25th?

    Do you *have* any posts made on the 25th?

    No. But why is it returning 2007-04-24 on the index page
    and 2007-04-25 on the category-index?

    Do you see what I want to happen?

    I want the same 3 posts listed under “previously”, I don’t want that to change at all.

    Is it showing 2007-04-25 because that’s the date that I created the category-index PAGE? If so, how would you change the date the page was created?

    Any ideas here? I don’t have a clue with this PHP stuff.
    I just copy and paste bits and pieces I find from support topics or the docs that do what I need to do.
    So if I don’t find answers here, then that’s it. I’m a designer, not a database programmer.

    I just want the category sidebar to look exactly like the index sidebar.

    I’m in the wordpress IRC channel if any of you smart guys would like to help me out with this in real-time 🙂

    irc.freenode.net

    /join #wpmu

    my nick is ryanoz

    as you can see, i’m getting desperate

    We don’t read this forum moment by moment. It’s not like we get paid to help you, you know. So don’t expect a quick response, please.

    Is it showing 2007-04-25 because that’s the date that I created the category-index PAGE?

    Yep.

    If so, how would you change the date the page was created?

    Edit the database, change the post_date and post_date_gmt for your page’s post.

    We don’t read this forum moment by moment. It’s not like we get paid to help you, you know. So don’t expect a quick response, please.

    I realize this, believe me. I at least wait 30 mins 🙂 Surely you understand like all of us how frustrating it can be when your stuck, and all you can do is sit and wait for a response on this forum; not knowing if it will be 5 mins. or 5 days.

    And I’d be happy to pay you or anyone that can solve any issue I have, seriously. In fact, I would rather it be that way. If your interested, let me know.

    Edit the database, change the post_date and post_date_gmt for your page’s post.

    uhhh, apparently you missed my whole “i’m not a database programmer” comment. I have no idea how to modify the database. However, I am looking into this plugin as a solution… would you know how to change the PAGE’s date with this:
    http://guff.szub.net/2005/02/22/post-updated/

    ryanoz,
    Can you discribe what exactly what you want under “previously” rather than let us guess and confuse you more?

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Why is the value of this variable changing?’ is closed to new replies.