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

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 ) ); }


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


3

You can do this with pre_get_posts. This hook is called after the query variable object is created, but before the actual query is run. For excluding category id 32 and 39 from homepage, you can setup a function like this. function wpse_exclude_categories( $query ) { if ( is_admin() ) return; if ( $query->is_home() && ...


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

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

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


2

WordPress' terms and taxonomies are spread over three tables in the database. Those tables are wp_terms, wp_term_relationships and wp_term_taxonomy - see the codex article on Database Description for more details. The parent relationship is part of the wp_term_taxonomy table, so you should inspect the differences between your environments in this table. ...


2

Just a quick outlined draft of an idea, so beware I haven't thought and tested this through entirely. I'm certain though that you can perform sorting actions this way. Ok, what I was thinking is, why not hooking into the_posts and use usort to do the sorting. All the rest, especially the conditionals are just to make sure that this isn't performed on every ...


2

You should check for category posts to modify content. Specify category ID (integer), name or slug (string), or an array of these in in_category check. function my_image_tag( $html, $id , $alt, $title ) { if ( in_category( '1' ) ) { $html = "<div class='my-class'>" . $html . "</div>"; } return $html; } add_filter( ...


2

There is no way easy way to do that. You have to query directly to achieve that. I am assuming, you only want the parent categories which don't have descendants or even if they have descendants, it's not used in any post global $wpdb; $categories = $wpdb->query("SELECT $wpdb->terms.* FROM $wpdb->terms ...


2

Instead of if ($post_id->post_category[0] == 18) try if ( $post_id && in_category( 18, $post_id ) ) Also the 'save_post' action should be add_action('save_post','my_meta_save', 10, 2); If you want the metabox to appear on a new post when the category is selected, then remove the outer category test if statement so that the metabox is always ...


2

You are using get_categories() function and this function have not 'depth' argument. Also php is not supporting $cat-id variable. it would be $cat_id. So try this kind of code: $cat_id = get_query_var('cat'); $args=array( 'parent' => $cat_id, 'hide_empty' => 0, 'orderby' => 'name', 'order' => ...


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


2

Assuming your query does indeed have multiple post types, you'll want to pluck them out before continuing (I assume you're using $wp_query as your WP_Query object): <?php $all_post_types = array_map(function($item) { return $item->post_type; }, $wp_query->posts); // Now we get a unique list of post types: $unique_post_types = ...


2

Your problem lies in this piece of code $categoriaActual = get_the_category($post->ID); $idCategoriaActual = $categoriaActual[0]->term_id; The first line gets the categories that belongs to the post in an array, that is fine (Just one note, when inside the loop, you don't need to pass the post ID, that is done by default). Your ...


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

Take a look the section called Preserving Existing Query Parameters on http://codex.wordpress.org/Function_Reference/query_posts Try merging in the existing query parameters; they might be getting overridden. Instead of: <?php query_posts('cat=4'); ?> try global $query_string; query_posts( $query_string . '&cat=4' );


2

category__in will never work as you aren't making use of the build in taxonomy category. You are actually making use of a custom taxonomy called tagbbt. Take a look at this post, I have explained what the differences are For custom taxonomies, you need to make use of a tax_query Here is an example $args = array( 'post_type' => 'bbt', ...


2

Your $args array is incorrect. You used cat=-8 which is not correct here. You will have to specify/exclude category this way 'cat' => -8. So your $args array will be $args = array( 'posts_per_page' => 3, 'orderby' => DESC, 'cat' => -8 );



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