Get user’s most published categories

This can be done easily with $wpdb, here’s my approach: function GetTop2CategoryByUser($user_id, $taxonomy){ global $wpdb; $results=$wpdb->get_results( $wpdb->prepare( ” SELECT tt.term_id as category, COUNT(p.ID) as count FROM $wpdb->posts p JOIN $wpdb->term_relationships tr ON p.ID = tr.object_id JOIN $wpdb->term_taxonomy tt ON tt.term_taxonomy_id = tr.term_taxonomy_id AND (tt.taxonomy = %s AND tt.term_taxonomy_id != 1) WHERE p.post_author = %s GROUP … Read more

Authors in menu, template list post by author

By default, you can view posts by authors with a URL of the form {home_url}/author/{author-slug}/ If you’ll be writing any PHP and need to output a link to an author’s posts, see the function get_author_posts_url. Edit: If you’ll be writing your own author post page template, the filename should be one of the following formats: … Read more

post_parent is 0 when uploading new files

The reason was the post_id key simply missing from the upload query. It was there for the normal posts, but was being omitted in the custom-post-type uploads. No idea why. The issue had something to do with the javascript uploader settings. So I’ve asked another question regarding the pluploader here and have managed to find … Read more

Hide Post comments when displayed via WP_Query

The problem You must remember to call the core function wp_reset_postdata(), after your while loop, to restore the global $post object. The comment form is relying on that object, that you override with your $queryPosts->the_post() call. Note that the extract() isn’t recommended, check this answer by @toscho, for example. Removing comments To remove the comment … Read more

wp_insert_post question [closed]

You need to add slashes as wp_insert_post will remove them: $data = array( ‘post_content’ => ‘[code] #include<stdio.h> int main() { printf(“Hello World\n”); return 0; } [/code]’, ); wp_insert_post( wp_slash( $data ) ); Update: After running the above, this is exactly what I get in the editor: [code] #include int main() { printf(“Hello World\n”); return 0; … Read more

New blog template to display only one category

If your theme is creating a new query for the main page loop it is doing something very wrong. To get a category archive, all you should need is a template named according to one of these patterns, depending on your need: category-{slug}.php – If the category’s slug is news, WordPress will look for category-news.php. category-{id}.php – … Read more

get_post_field – Title without paragraph

As per the discussion the_content is not a proper hook for filtering post titles while it filters the post content. wpautop() function is called with the_content so it adds the necessary paragraphs. To filter post titles use the_title instead, it won’t add any markup tags by default: echo apply_filters(‘the_title’, get_post_field(‘post_title’, $post_id));