Divide the list into two columns (get_posts)

You could do this with the modulo operator. $posts = get_posts($args); $html=”<ul>”; $limit = 5; $i = 1; foreach ($posts as $post) { $html .= ‘<li>’ . $post->post_title . ‘</li>’; if($i % $limit == 0) { $html .= ‘</ul><ul>’; } $i++; } $html .= ‘</ul>’; echo $html;

Select objects from get_posts()

This sounds like more of PHP question than a WordPress one – get_posts() just returns an array of objects; interact with them like you would any other numerical array: $posts = get_posts(); $first_post = $posts[0]; $last_post = array_slice( $posts, -1, 1 ); $everything_but_first_last = array_slice( $posts, 1, -1 ); Check out the complete list of … Read more

get_posts by id not working

I have just found an alternative solution: global $post; $current_post = $post->ID; $array=range(1,$current_post); $args = array( “numberposts’ => 5, ‘offset’ => 0, ‘category’ => $category->term_id, ‘orderby’ => ‘ID’, ‘order’ => ‘DESC’, ‘exclude’ => $current_post, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘suppress_filters’ => true, ‘post__in’ => $array ); $posts = get_posts($args); I’m not sure why the … Read more

Add ul to its children with get_posts

//first let’s separate all the top level pages & child pages $top_lvl = array(); $children = array(); foreach ( $values as $post ) { if( $post->post_parent ) { $children[$post->post_parent][] = $post; } else { $top_lvl[] = $post; } } //now we have all top level pages in $top_lvl //& we can access their child pages … Read more

List random posts on single page in the current category

This happens because you use a foreach loop on post categories. You can display random posts from the first returned category by getting rid of the foreach loop and using $categories[0]->term_id as your category in query args. You can also try to grab all the category IDs for all your categories and include them as … Read more

Working with get_posts parameters/arrays/strings

How do I get dynamic parameters into the array,… This example from the Codex demonstrates that: $paged = get_query_var( ‘paged’ ) ? get_query_var( ‘paged’ ) : 1; $sticky = get_option( ‘sticky_posts’ ); $args = array( ‘cat’ => 3, ‘ignore_sticky_posts’ => 1, ‘post__not_in’ => $sticky, ‘paged’ => $paged ); $query = new WP_Query( $args ); Both … Read more

Sort get_children by menu_order

Following WordPress 3.5, gallery shortcodes now include the image IDs by default. Like this which also holds the order, so open the plugin file named carousel-gallery-jquery.php and replace this line: (around line 140) $attachments = get_children( array(‘post_parent’ => $id, ‘post_status’ => ‘inherit’, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘order’ => $order, ‘orderby’ => $orderby) ); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)