Query next days from today in wordpress - wordpress

I have a creepy site running Wordpress 2.8.5. Its purposed to show events in my state (Bahia/Brazil).
Every event has it published date as the day of the event and the theme shows future posts bypassing WP's default to display until today.
It has a slide with some featured events and this is how it now selects what is to be shown in the slides:
$mes = date('n');
$ano = date('Y');
query_posts("
meta_key=dest_principal&
meta_value=1&
showposts=6&
year=$ano&
monthnum=$mes&
order=ASC
");
With this code the slide shows the first 6 posts in the current month. The problem I have is not being able to show the next 6 posts begining today. (to be clear, by today i mean the day of access)
I found this entry " wordpress query - next two events by metadata date " but could not translate it to my need.

It's not clear exactly what you're trying to do. Are you trying to show 6 posts starting from today and going back to the 6 previous posts? So essentially the 6 newest posts?
If so try this in place of query_posts...
$recent = new WP_Query("cat=3&showposts=6");
while($recent->have_posts()) : $recent->the_post();
You can use the 'cat=3' to display posts from a particular category, just change the '3' to your category id. Otherwise if you don't need to do this remove this 'cat=3&'.
BTW, I have a site focused on Bahia if you're interested in a link exchange get in touch.

Related

My code is duplicating my wp posts

I have written some php code that loops through the published posts on my wp site and when the Expiry Date (new field I added to each post) is <= to today's date, the post status is changed to draft.
It does change the status to draft however it duplicates the post. So I end up with 2 of the same posts, both set to "Draft".
I just want the original post status changed and that's it.
Not sure what I'm doing wrong here.
The echo statements are just for me testing the code.
Below is some of my code:

Pagination in application which use firebase.com as database

Front end application will use firebase.com as database.
Application should work like blog:
Admin add / remove posts.
There are "home" page which show several articles per page with "Next" and "Prev" buttons and page which show single article.
Also I need deep linking.
I.e. when user enter URL http://mysite.com/page/2/ I need that application show last articles from 10 to 20, when user enter URL http://mysite.com/page/20/ application show last articles from 200 to 210. Usual pagination.
Main question - is it possible to achieve this if use firebase.com.
I read docs at firebase.com, I read posts here. "offset()" and "count()" will be in the future, use priority, in order to know count of items and not load all of them use additional counter.
Based on this I suppose this:
ADD POST action:
get value of posts counter
set priority for new post data equals to value of posts counter
increase value of posts counter
DELETE POST action
get value of priority for post data
query posts data which have value of priority more than priority for post data which will be deleted and decrease their value
decrease value for posts counter
GET POSTS FROM x TO y
postsRef.startAt(null, x).endAt(null, y).on(... and so on)
Thing which I not like in this way are actions for DELETE POST. Because index of posts will be from 0 to infinity and post with less priority is considered as post which was created earlier so if I have 100000000 posts and if I need to delete 1st post then I need to load data for 99999999 next posts and update their priority (index).
Is there any another way?
Thanks in advance, Konstantin
As you mentioned, offset() will be coming, which makes your job easier.
In the meantime, rather than using startAt and endAt in combination, you could use startAt and limit in combination to ensure you always get N results. That way, deleted items will be skipped. You then need to check the last id of each page before moving to the next to find the proper id to start on.

Inserted Wordpress Post Shows Bad Date In RSS Feed

Our wordpress blog (currently version 3.4.2) has an external process that inserts posts directly into the database from a third party. I don't have the ability to change that, so don't bother telling me it shouldn't be done that way. I CAN change the insert statements though.
The posts show up and everything looks fine except that the RSS feed shows an invalid year (expecting 2013, instead getting -0001) in the date field:
<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
The post_date field in the wp_posts table for the post shows the correct date, and on the site the post has the right date. It shows up in the right place chronologically.
If I manually edit the post using the control panel and change the date even by just one second and re-publish the post then it fixes the feed.
This problem causes the RSS feed to not validate, and it's breaking other things. Help!
There are 4 dates stored for each WP post: Post_date, post_date_gmt, post_modified and post_modified_gmt.
I recommend you to insert the same date for both post_date and post_modified and see if it works.

Wordpress Most recent Comments at top with Per page resctriction

I am using roots wordpress framework. I need to show comments of posts in Desc order by posted date , means the most recent shows at top.
If I use this in my commnets.php, it works fine
wp_list_comments(array('callback' = 'roots_comment','reverse_top_level'=>true,'reverse_children'=>true,'type'=>'comment'));
But if I try to restrict the number of comments , then it ignores the reverse arguments and shows the comments from bottom.
wp_list_comments(array('callback' => 'roots_comment','reverse_top_level'=>true,'reverse_children'=>true,'per_page'=>3,'type'=>'comment'));
Now this one is showing the first 3 comments from bottom(3rd,2nd ,1st ) in this order(means order is correct but it is counting the 3 comments from bottom, rather than the recent 3 submitted ) .
Does anyone know solution to this , apart from changing the core wp-includes/comments-template.php file . I can't do that as it is a multisite , so it will affect the other sites comment order.
Thanks
You should have an easier time modifying your settings by logging into your Dashboard and checking out Settings->Discussion.

In Wordpress: Group same-day posts on the index page

i'm looking for a way to code the loop in such a way that it places posts that are in the same day within a div. Im doing this so I can put a separator between the different days to show users that they are looking at another day. An example of this in action is in informedlondon.com, where once a days worth of posts ends, there is a little graphic in between to separate the posts. This is what Google's Blogger platform does by default, thats why it was easy for the divider to be put between the different days of posts.
I'm guessing there must be a tutorial about it somewhere but I have checked and can't seem to find one. I have a sneaky suspicion that it's very easy and i'm just being a dunce. Would appreciate some help.
Many thanks in advance.
The simplest method to accomplish things like this is to 'hold' the current date in a variable. Before your loop: var $current_date and then inside your loop, a simple if statement:
if( $current_date != get_the_date('d-m-Y') ){
echo '<h2>Posts for '.get_the_date('d-m-Y').'</h2>';
$current_date = get_the_date('d-m-Y');
}
So in effect, you're checking with each post whether the date of the post is different than the date of the last post rendered (in the 'holding' variable, $current_date). If it is, you print a title with the new date, and set the 'holding' variable to the new date. If not, nothing happens and the post is printed as usual.

Resources