Tag Info

Hot answers tagged

12

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


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


5

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


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

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

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

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


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

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


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

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

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

The functions accept an $in_same_cat argument, the default value of which is false. Just set that to true. previous_post_link($format, $link, true); next_post_link($format, $link, true);


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

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

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

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


2

You need to create taxonomies specific to your post type using register_taxonomy instead of using the taxonomies argument when registering the post type. http://codex.wordpress.org/Function_Reference/register_taxonomy // categories register_taxonomy( 'project_categories', 'projects', array( 'label' => __( 'Categories' ), 'rewrite' ...


2

You are trying to echo PHP code. Additionally you are using single and double quotes wrong. You should just fix the formatting of your echo() functions. Something like this: echo '<div id="requestsample"><a class="fancybox button" href="#contact_form_pop">Request a Sample</a><div class="fancybox-hidden" style="display: ...


2

You just need get current date and add it on data_query in wp_query, Look this: <?php $getdate = getdate(); $args = array( 'date_query' => array( array( 'year' => $getdate["year"] ), ), ); $query = new WP_Query( $args ); ?> and then use loop: <?php if ( $query->have_posts() ): while ( ...


2

You are way off, if you say that wp_publish_post() has been renamed to {$new_status}_{$post->post_type}. The latter actually is a hook, while the former is a function. Where the latter is part of the former, because it's part of wp_insert_post. The hook {$new_status}_{$post->post_type} is part of wp_transition_post_status() - additionally see the ...


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


2

You can specify multiple categories within has_category like so: if ( has_category( array( 'category_1', 'category_2' ) ) { // do something } However, I am not sure if this acts as AND or OR, meaning does it require that ALL categories specified are matched, or one of the X supplied (category_1 OR category_2). In any case, your syntax should work ...


2

Edit If this is your goal: I want to use the Wordpress gallery to show all pictures of one category in a gallery (on a fixed page), which I do not have to update all the time by inserting the pictures manually. Then the easiest way to accomplish it is via custom page template. Create the template Copy your page.php template file, and name it ...



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