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

Posts being viewed

I would suggest a way to implement this to be in the post template have a call that updates post meta with the current timestamp. Then you can show posts that have been viewed recently by querying meta data for all values within a certain time range ordered by that timestamp.

Internal linking to posts permalink fail because of spaces and stripe at postname

Spaces are invalid characters in URLs. Your links are broken, whether the posts exist or not and regardless of whether you want the spaces or not. And uppercase/lowercase can get you in trouble too. Some servers are case sensitive so if you have a permalink to http://somesite.com/hello-world a link like http://somesite.com/Hello-World might work or it … Read more

List latest posts with least comments in WP-Admin

I managed to figure it out. So, get_posts() uses WP_Query() and we can use the example in the documentation to filter the dates. Now for the comments, that is easy, we just add the parameter ‘orderby’=>’comment_count’. Also to note, when filtering get_posts(), we will need to disable suppress_filters. Let’s filter the time first: function filter_where( … Read more

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