Tag Info

Hot answers tagged

18

Taxonomies, as previously described are a collective noun for the following category post_tag post_format link_category custom taxonomy The first four are built-in taxonomies, while custom taxonomies are taxonomies that are manually created by the user with register_taxonomy. Custom Taxonomies can be hierarchical (like the build-in taxonomy category) or ...


6

The Automatic Sponsor Posts Injector: Here's one idea based on my answer for the question: How to show Y number of custom posts after every X normal posts? I hopefully made it a little bit more useful here on Github, but it may be refined much more (future work). The SponsorPostsInjector class will help you to automatically inject the sponsor posts into ...


6

EDIT REVISIT NO 2 I have never touched the Transient API, until today when I saw @MikeSchinkel answer in this post. This inspired me to revisit this post once again. After some testing, I came up with the following: Time to execute went down from ~0.07 seconds to ~0.002seconds Database query time went down by about halve With the transient, only 2 db ...


5

Category, Tag, Link Category and Post Formats are built in taxonomies. From Codex Basically, a taxonomy is a way to group things together. The names for the different groupings in a taxonomy are called terms. Using groupings of animals as an example, we might call one group "birds", and another group "fish". "Fish" and "birds" are terms in our ...


5

Here's a simplified combination of both @PieterGoosen and @ialocin fine answers by using the loop_start hook: add_action( 'loop_start', function( $q ) { if( $q->is_main_query() && $q->is_category( 'car' ) ) usort( $q->posts, function( $a, $b ){ return -1 * has_tag( 'bmw', $a ) + 1 * has_tag( 'bmw', $b ); ...


4

Your terminology is a bit scrambled here. A custom taxonomy is a taxonomy which you manually register through register_taxonomy. In your case that is ait-dir-item-category. Any "category" (as you call it) you create in your custom taxonomy is called a term. In this case events. To create a custom page for events, you need to name your template ...


4

This should hopefully do the trick: /** * Append the image categories to the current image class. * * @see http://wordpress.stackexchange.com/a/156576/26350 */ add_filter( 'get_image_tag_class', function( $class, $id, $align, $size ) { foreach( (array) get_the_category( $id ) as $cat ) { $class .= ' category-' . ...


4

Here is the code to get category based previous and next links on posts $post_id = $post->ID; // current post id $cat = get_the_category(); $current_cat_id = $cat[0]->cat_ID; // current category Id $args = array('category'=>$current_cat_id,'orderby'=>'post_date','order'=> 'DESC'); $posts = get_posts($args); // get ids of posts retrieved ...


4

You can use get_categories() function. <?php $cats = get_categories(); $count = 15; // Total Categorie $linetotal=round($count/3); ?> // Part of Categorie <div class="category_list"> <ul><?php $totalcount = 1; $totalpart = 1; foreach($cats as $cat): ?> <li><?php echo $cat->name; ...


4

You can use the category__in argument: // use get_the_category( $post_id ) if you are outside the loop $categories = get_the_category(); if( $categories ){ $related_posts = get_posts( array( 'category__in' => $categories ) ); }


3

// Getting Parent ID $parent = get_term_by( 'name', 'Session 2015', 'category'); // Checking if SubCategory Exist. $term = term_exists('Photos', 'category', $parent->term_id); //if Exist Do the query if ($term !== 0 && $term !== null) { $query = new WP_Query( 'cat='.$term['term_id'] ); } References: term_exists get_term_by


3

A lot of time since this quesiton and answer were posted. Since then things has changed a lot. The typical recommendation about disallow crawlers to access wp-content/themes, wp-content/plugins, wp-content/cache, wp-includes, and any other directory that contains CSS or js files needed in the site, are no longer valid. For example, lets talk about Google. ...


3

You can make use of the hide_empty argument of get_terms(). It's default value is set to true. Do it somewhat like this: $args = array( 'hide_empty' => false ); $terms = get_terms( 'wpsc_product_category', $args );


3

You cannot do this type of sorting inside the loop. You can however be done by writing your own function Here is my solution: PS! Needs PHP 5.4+ STEP 1 Create a function called wpse161553_loop_sort($tag=''). This will work with a single tag with the main query. STEP 2 You need to get the post objects from the main query. They are already available and ...


3

You have a couple of flaws here and also a few places where you can optimize the code Instead of using get_the_category(), use wp_get_post_terms(). It is a bit faster, and you have the option to just get the term ID's from the post categories. This is one place where you can optimize your code ID is not a valid property of get_the_category(), it should be ...


2

Fist error I see is a syntax error: depth => 0 should be "depth" => 0 Second error is that you are using a category object like a post object. None of these lines will work: There is no post data to setup. Remove this line: setup_postdata($category); A category object has no category_modified property. Maybe you need the date of the last ...


2

Looking at the source code for wp_get_archives(), there is a filter called getarchives_join which you can use to restrict wp_get_archives() to a specific category You also need to get the current category ID, which is easy, simply use get_queried_object_id() You can try something like this to display archives for the currently viewed category add_filter( ...


2

Before I start again, I just want to reinforce the fact you should not run a custom query in place of the main query on your archive pages. Please see this post to learn when you should use a custom query and where not. I you do not switch back to the default loop, then my solution will not work In the previous post we have already solved the issue to only ...


2

Use the terms_clauses filter, which passes all the various components of the query (fields, join, where, orderby, order & limits), and implement your own "search" argument: function wpse_178511_get_terms_fields( $clauses, $taxonomies, $args ) { if ( ! empty( $args['surname'] ) ) { global $wpdb; $surname_like = $wpdb->esc_like( ...


2

I would recommend using the category_template filter - just check if the current category is an ancestor of 67: function wpse_179617_category_template( $template ) { if ( cat_is_ancestor_of( 67, get_queried_object_id() /* The current category ID */ ) ) $template = locate_template( 'category-slider.php' ); return $template; } add_filter( ...


2

We can get the categories via get_categories() function (which will get the same categories as wp_dropdown_categories() function), but as array and without the markup. As the value is returned as array, we can loop through the categories and generate the HTML ourself. Usually, we would aim for a structure like this: <select name="categories"> ...


2

Your argument for is_singular() is wrong It should be an array is_singular(array('post','movie')) You can read more about the argument passed from this link here


2

Notice that you don't need echo to display the result, since echo=1 is the default settings of wp_get_archives(). As @PieterGoosen explained, the wp_get_archives() function doesn't support the exclude parameter. But we can use _exclude_terms, the custom parameter of the wp_get_archives() function, to exclude posts with some given terms. Here's an ...


2

get_the_term_list() will not work here. The best function to use would be wp_get_post_terms() With the following assumption, this can work If a post only belongs to one parent, one child and/or one grandchild, you can order the terms by term_id. It is widely accepted that the parent will have a lower numbered ID than the child and the child will have a ...


2

That is totally normal behaviour. If you want to remove category base you will need to write some custom rewrite rules, not simple rules I must say. From my point of view, removing category base requires a extra job in each request that is worthless because it doesn't provide any advantage for SEO or for better site navigation. Some popular plugins, like ...


2

Try this <a href="/category/<?php foreach((get_the_category()) as $category) { echo $category->slug . ' '; } ?>"> Hope this helps.


2

I think it will be easier to make use of the category slug, and not the name. It is already in lowercase and hyphen separated if you have more that one word. The problem with using the name and adding hyphens is that you will not get a match and most probably just 404. %20 is how blank spaces is encoded in a URL. You can just replace $category->cat_name ...


2

NOTICE Option one section one is done with the other answer in mind. Section one is interchangeable and can be used with the other answer or my approach in section 2 of option one. You can either use my approach here or the approach from @JustinBell. The important section here is section 1 which sorts your loop according to your predefined order according ...


2

Use get_the_category to get the categories belonging to the post. You can then use $category->count to return the amount of posts for specific category attached to the post Example: If a post has just one category attached to it, you can do the following $category = get_the_category(); echo $category[0]->count; In your check to see if there is ...


2

I am the lead developer of the Blubrry PowerPress plugin. As of this writing, there are 5 ways to approach this, each dependent on your goals. If each podcast can have the same branding (aka web site theme and domain name), then the following are all excellent options available in PowerPress... Category Podcasting - extend WordPress categories to ...



Only top voted, non community-wiki answers of a minimum length are eligible