Getting posts from some categories plus some individual posts

The problem here is that WP_Query requires the posts returned to be both in your lists of post IDs and in one of your categories. The SQL query generated by your code looks something like this: SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND wp_posts.ID IN (8200,3581,38,1562,7613) AND … Read more

Showing posts for today and future

Use get_posts function with WP_Query params instead of get_children. The code will than look like this: $today = getdate(); $pages = get_posts( array( ‘post_status’ => array( ‘publish’, ‘future’ ), ‘post_type’ => ‘event’, ‘sort_order’ => ‘ASC’, ‘orderby’ => ‘date’, ‘year’ => $today[“year”], ‘monthnum’ => $today[“mon”], ‘day’ => $today[“mday”] ) ); foreach ( $pages as $post ) … Read more

Trying to query all posts in category 4

For your issue regarding only returning 20% of your posts, try the following <?php query_posts(‘cat=4&posts_per_page=-1’); ?> Note: By default, 10 posts are returned. -1 will return all posts in the resulting set. http://codex.wordpress.org/Function_Reference/query_posts#All_Posts_in_a_Category — For your question about passing through the Category Name, you can pass through the category_name as parameter, which accepts the category … Read more

Limiting the amount of posts retrieved by the loop

The code you posted does not query for any content at all. To do that, use the WP_Query object. Please do not use query_posts, especially for secondary Loops. From the Codex: // The Query $the_query = new WP_Query( $args ); // The Loop while ( $the_query->have_posts() ) : $the_query->the_post(); echo ‘<li>’ . get_the_title() . ‘</li>’; … Read more

inserting a category into post

I haven’t tested the code below, but I think you could use something like it. add_shortcode( ‘show_posts_from_cat’, ‘wpse_85708_posts_from_cat’ ); function wpse_85708_posts_from_cat( $atts ) { extract(shortcode_atts(array( ‘id’ => ” ), $atts)); $args = array( ‘category’ => $id ); $cat_posts = get_posts( $args ); foreach( $cat_posts as $cat_post ) { setup_postdata( $cat_post ); // Display code here. … Read more

Display Related Posts by Category in Random

In the arguments for get_posts, add ‘orderby’ => ‘rand’. See get_posts in Codex for a full list of available arguments. $args = array( ‘category__in’ => $category_ids, ‘post__not_in’ => $showed_posts, ‘showposts’ => $SMTheme->get( ‘layout’, ‘relatedcnt’ )-$post_cnt, ‘caller_get_posts’ => 1, ‘orderby’ => ‘rand’ );

Find out in which kind of archive am I

Inspect get_queried_object(). On an archive for the category Uncategorized you get something like … stdClass Object ( [term_id] => 1 [name] => Uncategorized [slug] => uncategorized [term_group] => 0 [term_taxonomy_id] => 1 [taxonomy] => category Find out in which kind of archive am I => [parent] => 0 [count] => 8 [cat_ID] => 1 [category_count] … Read more