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

The documentation for register_post_type mentions a taxonomies parameter, giving it a value of array( 'category' ) will do what you want. There is also the register_taxonomy_for_object_type function


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

The error says it all, you are sending the request to a invalid host. Change this: var ajaxurl = 'http://my-site.co.uk <?php bloginfo("wpurl");?>/wp-admin/admin-ajax.php'; To: var ajaxurl = "<?php echo esc_js( admin_url( 'admin-ajax.php' ) ) ?>"; Note: from your code and description I'm assuming you are generating the jQuery code within ...


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

This same exact question was asked earlier this week or over the weekend, and it had me thinking. Here is the idea that I came up with. If you look at the source code of the WP_Query class, you will see that sticky posts is only added to the first page of the home page. There is also no filter supplied to change this behavior in order to set the required ...


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 ...


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. ...


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

Use the hooks added_term_relationship and deleted_term_relationships. These only fire when the relationship changes, as opposed to set_object_terms which always fires: function wpse_181090_object_terms_updated( $object_id ) { static $did = array(); // This function might fire multiple times for the same object, ensure it only runs once if ( ! ...


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

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

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

Pro tip - don't custom query unless you need to (you don't). And never use the guid field. if ( is_singular() && $cats = get_the_category() ) $cat_id = $cats[0]->term_id; // Category ID for current post elseif ( is_category() ) $cat_id = get_queried_object_id(); // Category ID for current archive else $cat_id = 0; // No cats $posts = ...


2

The permastruct /%category%/%postname%/ will include the categories and subcategories in the URL from top to first assigned child. So, if you want the URL be site.com/source/books/moby-dick/*postname*, you have to assign the post only to "Moby Dick". Assigning the post only to "Moby Dick" category will still show the post under "source" and "books" category ...


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

Thanks guys, I found a solution: It's as easy as adding the post_type_category element to the arguments object within register_post_type(): $args = array( 'label' => 'sausages', 'description' => 'Sausages', 'labels' => $labels, 'post_type_category' => 'food', 'supports' => ...


2

According to the plugins documentation (http://zahlan.net/blog/2012/06/categories-images/), this seems pretty simple: <ul> <?php $categories = get_categories( $args ); foreach ( $categories as $category ) { $img_src = z_taxonomy_image_url($category->term_id); if ( $img_src ) { echo '<li><img src="' . $img_src . '" ...


2

Just remove the trailing comma with some good ole php before echoing it out. $thelist = rtrim($thelist, ',');


2

As I have stated in my comments to your question Crappy written plugins always leads to some disaster at some time. In my opinion, delete that plugin and write your own code or find a properly written plugin. There is no use changing the damaged tire while the whole car is a complete write-off :-) Just to start off, never use query_posts Note: This ...


2

The fields returned by get_term_by() are: term_id name slug term_group term_taxonomy_id taxonomy description parent count So instead of $thiscat->ID, you should use $thiscat->term_id Ref: http://codex.wordpress.org/Function_Reference/get_term_by


2

SIDENOTE: This function can be used even if have posts belongs to one taxonomy only. You don't need to have a post that belongs to two or more taxonomies within the same hierarchy. I have made this function very flexible It is always a problem for me to display a category list or term list for a post if the following conditions occur Having a post having ...


2

You should always do the two following checks Check that your current query is the main query Check that the query is a front end query pre_get_posts alters all instances of WP_query, front end and back end, so you will need to make double sure you are doing the above checks Also is_category() should be an object of $query Your conditional should look ...



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