Tag Info

Hot answers tagged

14

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

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

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

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

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


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

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

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

Here is the code to get category based previous and next links on posts $post_id = $post->ID; // current post id $cat = get_the_category(); $current_cat_id = $cat[0]->cat_ID; // current category Id $args = array('category'=>$current_cat_id,'orderby'=>'post_date','order'=> 'DESC'); $posts = get_posts($args); // get ids of posts retrieved ...


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

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

Naughty boy you, you should never use query_posts. Straight from the codex: Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of ...


2

The issue is that there is no taxonomy meta data like there is for posts. ACF taxonomy data is stored serialized in the options table, so it can't be queried like post meta can. You have to load all terms and check the data associated to each one individually. Perhaps a better solution is to create Romance, Action, & Drama parent terms, and make your ...


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

Figured it out! The code below automatically lists all categories and each categories posts! $args = array( 'number' => $number, 'orderby' => 'title', 'order' => 'ASC', 'hide_empty' => $hide_empty, 'include' => $ids ); $product_categories = get_terms( 'product_cat', $args ); $count = ...


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


2

You should use Custom Post Type with hierarchical structure, which works same as Pages.


2

Have you try: function my_custom_show_pages_in_category( $query ){ if( $query->is_category() && $query->is_main_query() ){ $query->set('post_type', array('post', 'page' ) ) ; } } add_action('pre_get_posts', 'my_custom_show_pages_in_category' ); See more: Codex


2

There are several built-in CSS classes that come with the wp_nav_menu. In your case, you are looking for something like a current category class, which is not included. But we can easily add that to the CSS classes: function wpse_134409_current_category_class($classes, $item) { if ( is_single() && 'category' === $item->object ...


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



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