Articles of categories

Use get_term_children to get the sub category of a parent category for the current post

In my WooCommerce theme I’ve created a root category: ‘Brands’ then for each product I’ve added it’s brand as a sub category to the ‘Brands’ parent category. On the product page I want to display the brand of the current product. global $post; // Get the brands ID from slug $brands_id = get_term_by(‘slug’, ‘brands’, ‘product_cat’); […]

Retrieve all posts within tag OR category?

I’ve created a simple loop. And I have the following array for the query: $live_tags = array( ‘tag’ => ‘live’, ‘showposts’ => 5, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’ ); Where it says ‘tag’ => ‘live’, I need a logic that asks: if (‘tag’ == ‘live’ || ‘category’ == […]

Combining custom post type and post category

How can I query all the posts from either the custom post type (‘videos’) or with a post category (‘video’) in a loop? I’ve managed to create a query that combines the posts from a custom post type and the normal posts using the code below, but am struggling with achieving the same with a […]

WP_Query by a category id and a custom post_type

I need to query all posts that belong to a given category (default, not custom) and a custom post type. As simple as that. The fact that it doesn’t work, to me, is ridiculous. Unless I’m missing something? Here’s what I’ve tried: $args=array( ‘posts_per_page’ => 50, //’taxonomy’ => ‘category’, ‘post_type’ => ‘my_custom_type’ ‘category__in’ => array($cat_id), […]

Multiple menu items highlighted

I am using WordPress as the CMS for my website. For my navigation menu, I am using WordPress’ inbuilt navigation menu function. You add categories, page, etc, to this and it generates a list with certain classes you can style – like current-menu-item. My problem lies here: I have several categories in my menu, and […]

Remove 'rel' attributes from the_category() output

I am trying to get the categories associated with a post in it’s meta section by using the following code: <div>FILED AS: <span class=”gf-post-meta-result”><?php the_category(‘ &bull; ‘) ?></span></div> WordPress is generating the markup as: <div>FILED AS: <span class=”gf-post-meta-result”> <a href=”http://localhost/test/category/uncategorized/” title=”View all posts in Uncategorized” rel=”category tag”>Uncategorized</a> </span></div> This part rel=”category tag” is making my […]

Password protect a specific category page/post

I have searched high and low for this but nothing is sticking out at me. I am looking to password protect posts and/or pages based on a certain category. The reason for this is that I am creating a “members” side of things and want to keep things simple. If the post/page is in that […]

List all custom post type posts from a given category?

I have a custom post type myposttype and it’s taxonomy is called myposttype_categories. myposttype_categories have multiple terms inside, such as foo and bar. The tricky question is – how do I list all myposttype posts that belong to foo (or bar)? I thought this should work, but it does not: $args = array( ‘post_type’ => […]

If category is in parent category?

I have function that check what is main top category of post. So i have category tree like this Foo -bar –foobar cat2 and if post is in foobar, my function post_is_in_descendant_category shows me “foo” and i can style that post with style-foo.css. What i want now is to make this same possible for styling […]

Display posts in alphabetical order for a particular category

I`m looking for a solution to dispaly posts in alpahbetical order if category is “Glossary” otherwise display the posts in ascending order. When I tried the following code its works perfect for category Glossary,but the order of other posts went wrong. <?php global $query_string; if(is_category(‘Glossary’)) { query_posts($query_string . “&orderby=title&order=ASC”); while ( have_posts() ) : the_post(); […]