Pagination does not work with query_posts()

the_posts_pagination works with the global $wp_query, so your second method will not work. query_posts modifies the main query but the arguments passed will overwrite any existing values, so all values needed for pagination are lost when you set cat=5. But you can preserve the existing values by modifying the global query string. A more efficient … Read more

How to hook into creating a category?

There is a hook that can be used for any taxonomy, create_{$taxonomy}, which in your case, is a category. So, it would be create_category: add_action( ‘create_category’, ‘my_function’, 10, 1 ); This is triggered by wp_insert_term() at line 2142.

How to test if the post is in a primary category

You can use this code if you want to add an image in a specific category or a post. You can manipulate this code as you wish: add_filter( ‘the_content’, ‘add_a_image_in_post’ ); function add_a_image_in_post($content){ global $post; if($post->post_type == ‘post’){ //error_log(print_r($post, true), 3, WP_CONTENT_DIR.’/debug.log’); $all_cats = get_the_category($post); foreach($all_cats as $cat){ if($cat->slug == ‘sticky’){ return $content.”<img src=#1 >”; … Read more

Is there a way to order categories?

add_filter( ‘get_terms_args’, ‘wpse_53094_sort_get_terms_args’, 10, 2 ); function wpse_53094_sort_get_terms_args( $args, $taxonomies ) { global $pagenow; if( !is_admin() || (‘post.php’ != $pagenow && ‘post-new.php’ != $pagenow) ) return $args; $args[‘orderby’] = ‘slug’; $args[‘order’] = ‘DESC’; return $args; }

Category name as page title

You can change the code in the theme files to do this. Open the file category.php (if this file doesn’t exist, try archive.php) and replace the text you want to change with single_cat_title() Here is the documentation However these changes will be overwritten if you update your theme You can create a child theme or … Read more

WooCommerce – Get products from category right before deleting category

The hook delete_term_taxonomy fires before the category is deleted. If you look at the original code: /** * Fires immediately before a term taxonomy ID is deleted. * * @since 2.9.0 * * @param int $tt_id Term taxonomy ID. */ do_action( ‘delete_term_taxonomy’, $tt_id ); $wpdb->delete( $wpdb->term_taxonomy, array( ‘term_taxonomy_id’ => $tt_id ) ); /** * Fires … Read more