Exclude category by slug for for each loop

As I already stated, straight from the codex exclude (string) Excludes one or more categories from the list generated by wp_list_categories. This parameter takes a comma-separated list of categories by unique ID, in ascending order As you have stated, you have to use the category slug. To make this possible and dynamic, I think the … Read more

have_posts() return false but count says “3”

I had same problem. According to documentation: The hierarchy for a custom taxonomy is listed below: taxonomy-{taxonomy}-{term}.php taxonomy-{taxonomy}.php taxonomy.php archive.php index.php So, it doesn’t matter witch template file you are using, all of them will generate same issue. When I put in the beginning of template file code var_dump($wp_query);, i found this: public ‘request’ => … Read more

Display all authors and their only one latest post

In @Sagive SEO answer get_users_of_blog() is a depricated function. What is below code do get all authors display name and id in $authorsList Loop threw each author id and use WP_Query to get latest post of each author <?php $authors=get_users(); $i=0; //get all users list foreach($authors as $author){ $authorList[$i][‘id’]=$author->data->ID; $authorList[$i][‘name’]=$author->data->display_name; $i++; } ?> <ul> <?php … Read more

Custom Loop, Match Category with Page

If this is going in a page.php (or similar) template, then using query_posts() is a bad idea and could have some pretty bad consequences. I also prefer WP_Query over get_posts() as it easily allows you to use template tags and it explicitly exists for running secondary loops on a page. <?php global $post; $my_query_args = … Read more

Where should I use post_class()?

It’s actually only important to use it if your theme’s CSS or JS is reliant on something it outputs. It essentially stuffs relevant class names into the HTML tag you put it on based on the current post/category/blah/blah. So, on a single post template this: <article <?php post_class(); ?>> might output: <article class=”post post-123 category-3 … Read more

Transient not working for custom loops

I have actually worked on a post yesterday (check it out here) and was hit by the same problem. I’m also new to the Transient API, never actually worked with it :-). The problem here is that for a specific loop you need to use a certain value outside of your transient. You are simply … Read more

Loop code is displaying pages but not actual posts

Explanation in the comments: <?php /* This is your original loop (`have_posts`). Even on a custom template, the first loop references the PAGE to which your template is– this being your homepage. In order to display posts, you must use a new query, as in the next chunk of code. */ if ( have_posts() ) … Read more

What exactly defines a Main Loop and a Secondary Loop?

When you visit a link of your site, WordPress recognizes that link and understands (using the rewrite rules you have defined or using the query vars in the URL if there are no pretty permalinks) what is the request of the URL. After that WordPress, using this request, run a query. This is the main … Read more

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