Tag Info

Hot answers tagged

8

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 or not The categories and tags that you ...


7

You may want to try: do_action('set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids); this action is located at wp-includes/taxonomy.php add_action('set_object_terms','wpse5123_set_object_terms',10,4); function set_object_terms($object_id, $terms, $tt_ids, $taxonomy){ if($taxonomy == 'category'){ echo ...


7

After a bit of investigation... If you pass a category to is_category it uses get_queried_object to grab data-- see the source. get_queried_object returns NULL for categories that do not exist. You can demonstrate that with: function custom_posts_per_page($query) { var_dump(get_queried_object()); } add_filter( 'pre_get_posts', 'custom_posts_per_page' ); ...


6

If I understand well, you need to retrieve all the posts having category 'y' and also meta key 'facebook_shares', after that, you need the position of a specific post. My proposal is: Create a class that extends WP_Query and filter the results for required category and meta field. This class should also filter the SQL query to set the meta value as a ...


5

Turns out, this is a bug in the core. I was about to report it, but found out that it's been there for, like years, and applies to custom taxonomies as well. See tickets: #5809, #21950 and #22023. If all goes as planned, it's set to be fixed in 3.8 3.9 Future Release. Until then... In the meantime, here's a plan to overcome the issue — automatically set ...


4

You can do that by using category parameter in the wp_query change the line which looks like this $blog_query = new WP_Query( array( 'post_type' => 'post', 'paged' => $paged ) ); to $blog_query = new WP_Query( array( 'post_type' => 'post', 'paged' => $paged, 'cat' => 4 ) ); // Here '4' is the id of category you want to show, whereas you ...


4

WordPress select template, following its Template Hierarchy logic. What you have that is category archive, templates for individual pages are never considered for it. Also.. with the view of SEO, page.php is more important then category.php.. right? PHP template file is entirely back-end concepts, it doesn't have anything to do with SEO inherently.


4

Excluding categories with pre_get_posts() I found that excluding a category via pre_get_posts() and set_query_var() would work fine except for widgets. The Recent Post Widget would only exclude the category when using $query->set() instead. <?php /** * Does NOT apply to the Recent Posts widget. */ function glck1403271109_exclude_categories( $query ...


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

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


3

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


3

I think you could use the posts_per_page argument in your get_posts query: $args = array( 'child_of' => 1 ); $categories = get_categories( $args ); foreach ($categories as $category) { echo '<li><a>'.$category->name.'</a>'; echo '<ul>'; $posts_args = array( 'posts_per_page' => 9, 'category' ...


3

The original author isn't quite right in saying "which is merely the more elegant way to write". set_query_var() will always override the main query, whereas if you actually use: $wp_query->set( 'category__not_in', $excluded ); ... it will work for any instance of query_posts(), such as the recent posts widget.


3

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


3

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


3

First, I would solve your problem using WPQuery. Best to go there as opposed to query_posts Second, once you acknowledge and accept that WP Query is your friend for as long as you are within the wonderful world of WP theming, then you have to do as follows to solve your particular pickle: if(is_category('your_category') : $args = array( 'post_type' ...


3

By default the queries for category pages will only query the post post type, so in addition to registering the post type with category in the taxonomies argument, you have to modify those queries via pre_get_posts to get the CPT to appear on category pages: function wpa_illustrations_on_category_pages( $query ) { if ( $query->is_category() ...


3

get_terms just returns an array of terms, it doesn't generate output. You have to do something with that array to see the results- $categories = get_terms( "category" ); echo "<ul>"; foreach ( $categories as $category ) { echo "<li>" . $category->name . "</li>"; } echo "</ul>"; See the other examples on the Codex page.


3

The problem is query_posts(). It is stomping on the default query, and killing your pagination. Don't use query_posts(). Filter $wp_query at pre_get_posts instead: function wpse123674_pre_get_posts( $query ) { // Only modify the main query on the tag archive index if ( $query->is_main_query && $query->is_tag() ) { ...


3

SOLUTION Thanks to /u/G.M. /** Add New Field To Category **/ function extra_category_fields( $tag ) { $t_id = $tag->term_id; $cat_meta = get_option( "category_$t_id" ); ?> <tr class="form-field"> <th scope="row" valign="top"><label for="meta-order"><?php _e('Category Order'); ?></label></th> ...


3

Simply call the category_description() - this displays the description that you can enter for each category that you add in the admin UI under "category" (or post tag or each other custom taxonomy). You can as well use the underlying API function: term_description( $category, 'category' );


3

Okay, I've had a couple minutes free time, so I wrote up a small plugin. ;) The following goes into a new plugin file tf-restrict-categories/tf-restrict-categories.php: The introduction <?php /** * Plugin Name: Restrict Categories * Description: Individually restrict category combinations. * License: MIT * License URI: ...


2

From what I understand, the question is, how can you show only one category on a WordPress Page? What Scuba Kay is suggesting is the default category archive, if you want to go that route, WordPress already has archive pages with your posts for each category without you having to create your own Page. If you want to make changes to this archive page, you ...


2

Move what you are calling the "standard link ending" to the end of the function, instead of the beginning. class CategoryThumbnail_Walker extends Walker_Category { // A new element has been stumbled upon and has ended function end_el( $output, $category, $depth, $args ) { // Get one post $posts = get_posts( array( // ...


2

There is indeed a much simpler way to do this. First, to get the child category, just check the value of each category's parent. If it's a top-level category, the parent will be 0. So the child category will pass the test if( 0 != $category->parent ): $categories = get_the_category(); foreach( $categories as $category ){ if( 0 != ...


2

Wp_Query should be able to do this for you. Pass it the appropriate parameters, including a tax_query, and check found_posts. $p = new WP_Query( array( 'post_type' => 'custcpt', // your CPT 'tax_query' => array( array( 'taxonomy' => 'custtax', // your tax 'field' => 'id', 'terms' => $cat->term_id, ...


2

You can use the wp_insert_term() function to achive this. First create the parent category, then create a child category. $parent = wp_insert_term( 'Parent Category', // category name 'category', // taxonomy array( 'description' => 'Category description', // optional 'slug' => 'parent-category', // optional ) ); ...


2

You will need to use style parameter to define the type of list. And to remove <br /> tags from the list, set parameter 'echo' => 0 and str_replace to remove <br /> tag from the output. $args = array( 'orderby' => 'name', 'show_count' => 0, 'pad_counts' => 0, 'hierarchical' => 1, 'taxonomy' => $tax, ...


2

The problem with this is that to make the update method of widget class work, the name inputs on the form method should be setted via $this->get_get_field_name('name_of_the_field'); but wp_category_checklist has no argument to setup the name of the inputs (checkboxes). However wp_category_checklist uses a walker class to print the checkboxes and allow to ...


2

You want to select the option Custom Structure, not Post name, and insert /%category%/%postname%/ there. The Category base under Optional is the base for Category Archives, not single posts.



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