Tag Info

Hot answers tagged

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


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

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. Until then... In the meantime, here's a plan to overcome the issue — automatically set a custom slug ...


4

A category page is an archive page. So is_archive() will return true on a category page. Try to push down is_category() further, or use is_category() before is_archive(). Like This if ( is_search() ) { // Search Result content } elseif( is_category() ) { // Category archive content } // check for tag, taxonomy, date before elseif ( is_archive() ) ...


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

Put the following in your functions.php: function wp_list_categories_for_post_type($post_type, $args = '') { $exclude = array(); // Check ALL categories for posts of given post type foreach (get_categories() as $category) { $posts = get_posts(array('post_type' => $post_type, 'category' => $category->cat_ID)); // If no ...


4

Try to do all theme modifications in functions.php whenever possible. It keeps the theme files clean and uncluttered. Here's an example using the pre_get_posts action: function order_category_archives( $query ) { if ( is_category() && $query->is_main_query() ){ // is_category() can specify a category, if necessary $query->set( 'orderby', ...


4

The WordPress function switch_to_blog() expects an integer as an input parameter. You can read more about it in the Codex: http://codex.wordpress.org/Function_Reference/switch_to_blog Please try this kind of structure instead: <?php $original_blog_id = get_current_blog_id(); // get current blog $bids = array(1,2); // all the blog_id's to loop through ...


3

It sounds to me like genre should be its own taxonomy. Then posts get assigned to both categories and genres. If you do it this way, here's what you need to do to get everything working: First, register the taxonomy genre. Next, assuming you're using the core posts and categories, go to Settings → Permalinks. Set your permalinks to be ...


3

I did not actually test your code thoroughly, but on the first glimpse: your form input is named post_category while you're grabbing $_POST['new_cat']. Adjusting that (e.g., set both to post_category) should already do. // EDIT And why are you grabbing $_POST['category'] in line 5?


3

To get a list of all terms of taxonomy X whose posts are associated to terms from taxonomy Y too, we have to: Get all term IDs for both taxonomies Create a tax query to fetch all posts, because we don’t want to show empty term archives. Format the result in a hierarchical list. Let’s go! Getting the term IDs is simple: get_terms( $taxonomy_name, ...


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

From a plugin or your theme's functions.php file: function wpse106861_mod_query( $query ) { /* are we on the blog page ? */ if ( $query->is_home() && $query->is_main_query() ) { /* get ID of news category */ $news_id = get_cat_ID( 'news' ); /* exclude posts in new from query */ $query->set( ...


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

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

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

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

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

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

You want to change the tooltip... but to what? Sorry my crystal ball isn't quite working today. Here are some options you have: Change it in wp-includes/category-template.php but that's far from ideal since an update will overwrite this. You can add a function to your function.php file. For example if you want to remove it completely (since you didn't ...


2

Setting aside that you're incorrectly using query_posts(), the easiest solution is to add a call to post_class(), to output post-specific classes, including .category-{ID} and .category-{slug}: <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> <li <?php post_class(); ?>><a href="<?php the_permalink(); ?>" ...


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

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

You've to make use of the post_per_page or numberposts parameter of get_posts(). The parameter defaults to 5, see source, just chose the value you actually want it to have in your get_posts() call and the default value will be overridden.


2

The number of posts is set to 5 by default, so you have to set it to your liking. If you want to show all posts, then it's -1, and the number you want otherwise. You should also put functions out of loops (as in your second foreach), so here is your code, optimized: <?php $args = array( 'child_of' => 1, ); $categories = get_categories($args); ...


2

I remembered that once I had to do same thing and wrote a custom sql query... it was painful, as @Rarst said. However I'll post the function I wrote, and there isn't much to explain, is a complex SQL query where there is the intersection of 2 checks to get all the term of a specific taxonomy that are associated in post having a specific term in another ...



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