Permalinks: display just one kind of wp category in the posts url

Two things need to be done. First, make your posts URL is different using the post_link filter. function _20170117_post_link( $url, $post, $leavename ) { if( in_category( ‘news’, $post) ) { $url = get_site_url() . ‘/news/’ . $post->post_name ; } return $url; } add_filter( ‘post_link’, ‘_20170117_post_link’, 10, 3 ); Second, make the rewrite rule for this: … Read more

How do I toggle pagination on/off in search results and category listings via a link?

I think it should work by hooking into pre_get_posts: function wpse_254661_remove_pagination( $query ) { if ( $query->is_main_query() && get_query_var( ‘onepageprint’, 0 ) ) { $query->query_vars[‘nopaging’] = 1; $query->query_vars[‘posts_per_page’] = -1; } } add_action( ‘pre_get_posts’, ‘wpse_254661_remove_pagination’ ); Like this you can modify your query right before it gets fetched and the query object gets passed by … Read more

Add /category/ to an author archive page

You can achieve this by adding a new rewrite rule using ‘add_rewrite_rule`. If the category is the default WordPress category, you won’t have to register a query_var but if your category is a custom category, then you would have to register a query_var using the query_vars filter. If category is the default WordPress category: function … Read more

How to create a page which lists all categories with its ratings [closed]

Copy the entire function to the page that you want to have your average ratings: <?php // Lets get the id of every existing category $output_categories = array(); $categories = get_categories($args); //We loop through every category to calculate the average rating score of it’s posts foreach($categories as $category) { $post_ids = get_posts(array( ‘numberposts’ => -1, … Read more

How to Add Default Content for all Category Pages Before and After Content?

If I understand you correctly, you want some default content if you create a new post in the category “store”. Try to use the_content() filter here: add_filter( ‘the_content’, ‘add_default_content’ ); function add_default_content( $content ) { //run only when we are in the category “store” //could also be “coupons” if ( in_category(‘store’) ) { //define your … Read more