query_posts does not return old posts? - wordpress

I'm using query_posts on my home page to fetch articles from multiple post types. I'm using following code to do so.
<?php query_posts( array('post_type' => array('post','page','custom_post1','custom_post2','custom_post3','custom_post4','custom_post5','custom_post6')));
if (have_posts()) : while (have_posts()) : the_post(); // begin the Loop ?>
/*html code goes here*/
<?php endwhile; endif; ?>
It fetches the posts rightly, but the problem is: it does not fetch old posts. So for example I have 1 post and its publish date is 02/july/2012, this post won't be displayed on my home page. But as soon as I update the date to 02/Aug/2012 it starts showing up on Home page.
So is there any code I can add in query_posts that will enable older posts to be fetched too.

Wordpress by default fetch 10 posts or number of posts set by user from admin.
query_posts accept argument that return number of record.
query_posts( 'posts_per_page=5' );
query_posts( 'posts_per_page=50' );

Related

Drag and drop and updating menu-submenu combine with menu in wordpress

I have created custom functionality for changing order of published pages and posts and private pages and posts programmatically. But how can I make that listing as menu/sub-menu items in main menu programmatically.
You can use Short codes in menu.
First, use this snippet in functions.php to add shortcode support in wordpress menu :
add_filter('wp_nav_menu_items', 'do_shortcode');
then, you can create shortcode to show your last posts and use in into your menu.
for example :
<?php
// function that runs when shortcode
function show_last_post_shortcode() {
// WP Query Parameters
$the_query = new WP_Query( 'posts_per_page=5' );
while ($the_query -> have_posts()) : $the_query -> the_post();
?>
<li><?php the_title(); ?></li>
<?php
// Repeat the process and reset once it hits the limit
endwhile;
wp_reset_postdata();
}
// register shortcode
add_shortcode('show_last_post', 'show_last_post_shortcode');
?>

Wordpress - Three custom posts with the same slug

I have three posts that have the same title and address, if I am logged in it displays my posts at all, but it logs out can not see them and shows me 404 if we can somehow read these posts?
i read post with this:
<?php while ( have_posts() ) : the_post(); ?>
<?php
get_template_part('templates/content', 'single');
?>
<?php endwhile; // end of the loop. ?>
I think your posts are private posts. Just edit a post from them and check at the right side of your content editor. There are few options, make this post public and then click on update.
Now check, your issue got resolved.
Go through this article for more info : http://en.support.wordpress.com/posts/post-visibility

Wordpress category

This is code from my wordpress homepage template. There are 3 same code, like this one bellow. The question is how can I put different categories to show different news when I post. At the moment code is same on my homepage and it show only category named World, it's the first category created. How can I setup the rest of code with different categories.
Currently it's like this : http://zaslike.com/files/os8hvxg38oendfwcvrz6.png
I need to put other categories instead same three.
http://justpaste.it/e0nh - Here is the code of homepage template.
I believe you are asking for this:
<!-- Your Query -->
<?php // The Query
query_posts( array ( 'category_name' => 'change-to-category-name', 'posts_per_page' => 1 ) ); ?>
<?php // The Loop
while ( have_posts() ) : the_post();?>
// YOUR HTML GOES HERE
<?php endwhile; ?>
<?php // Reset Query
wp_reset_query(); ?> // DON'T FORGET THIS
Use this code at the parts of the site that display your categories change the categories name to the ones you want to display and you are good to go.
Good luck welcome to SO.

Wordpress - Two loops on author.php?

Normally if I was doing more than one loop on a page, aside from the main wordpress loop, I'd just use wp_query, however when the author.php template is being used I can't see how I could use that, since I'd have to pass some args.
Pulling posts from categories or by date etc is all easy enough with wp_query, even getting posts by author ID can be done, but it needs to be generic, ie get posts from the current authors page.
Now, using the same loop as my category page I can easily generate posts on the author.php, but I need a second loop and I just can't figure out how to do it.
First loop would be pulling one random post and it's featured image, second would be getting the archive of that authors posts.
Any ideas?
Does this give you a list of the author's posts? If so, it should be easy to modify the arguments for WP_Query to get exactly what you want.
See here for all the options: http://codex.wordpress.org/Class_Reference/WP_Query
<?php
$new_loop = new WP_Query( array(
'post_type' => 'post',
'author' => get_the_author_meta('ID')
) );
?>
<?php if ( $new_loop->have_posts() ) : while ( $new_loop->have_posts() ) : $new_loop->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; else: ?>
Sorry, nothing was found.
<?php endif; ?>
<?php wp_reset_query(); ?>

How can I display a list of WordPress custom posts?

I am using WordPress 3, and I created a custom post type called article, which gives me the URL format of mywebsite/articles/article-title. How do I see all the article entries in the URL mywebsite/articles?
Assuming you set up everything correctly and you want to see the post type on a public template page, try this code into mycustomtemplate.php or the equivalent.
<?php $loop = new WP_Query( array( 'post_type' => 'article', 'posts_per_page' => 10 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php endwhile; ?>
You can customize the loop just like you would blog posts and pages. If you want to get all on one page you'll want to remove the limit of 10 on post_per_page I wouldn't suggest it though. I would say set it to 50 or 100 and still use pages.
Source: Custom post types in WordPress
I have the simplest solution. Just create file archive-{custom post type}.php and then, just do loop content as usual.
If you already set the permalink, just type yourdomain.com/{custom post type}.
You can easily achieve this from the definition of your custom post type, starting with WP 3.1. Just set has_archive to true.
Source: http://codex.wordpress.org/Post_Types#URLs_with_Namespaced_Custom_Post_Types

Resources