Limit amount of categories displayed in a post

In your functions.php, you can filter the_category_list, which is an array of categories for a post. function wpse_the_category_list( $categories, $post_id ) { return array_slice( $categories, 0, 2, true ); } add_filter( ‘the_category_list’, ‘wpse_the_category_list’, 10, 2 ); And then display the categories in your template file with: the_category();

‘posts’ table should not store the absolute image path

Well, after a little research I realized that it is an (inconvenient) feature of WordPress to store the absolute path of the images and other files, something that I completely disagree with. In any case, I discovered this plugin https://wordpress.org/plugins/root-relative-urls/. It does not fix the urls of files already inserted, but it corrects those of … Read more

Counting Posts by Category

0 down vote accepted I think it would help you to read this => http://wordpress.org/support/topic//display-number-of-posts-per-category function number_postpercat($idcat) { global $wpdb; $query = “SELECT count FROM $wpdb->term_taxonomy WHERE term_id = $idcat”; $num = $wpdb->get_col($query); echo $num[0]; }

If user has 1 post then dont let him create new one [closed]

You can use count_user_posts function. If the posts are getting saved as WordPress posts then it can be done by the snippet below: if (is_user_logged_in()){ $userPostCount = count_user_posts(get_current_user_id()); if ($userPostCount > 1){ $user = new WP_User(get_current_user_id()); $user->add_cap(‘publish_posts’,false); } else { $user->add_cap(‘publish_posts’,true); } }

I want to show recent post according to category of the post in single.php?

Have you tried researching about wp_query? Also here’s a basic looping according to category : $args = array( ‘post_type’ => array(‘post’), ‘order’ => ‘DESC’, ‘category_name’ => ‘test’, ); // The Query $query = new WP_Query( $args ); // The Loop if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); // Your custom code … Read more

Disable pagination in posts and pages

function wpse_disable_pagination( $query ) { if( $query->is_single() && $query->is_page() ) { $query->set( ‘nopaging’ , true ); } } add_action( ‘pre_get_posts’, ‘wpse_disable_pagination’ ); NOTE: nopaging (boolean) – show all posts or use pagination. Default value is ‘false’, use paging.

Display Custom Post Category Count & WordPress Category Count Using Shortcode

It’s because you are have passed “category” in “get_terms_by()” function as third argument. Please replace “add_custom_taxonomy_here” with your custom taxonomy slug in below code. // Add Shortcode to show posts count inside a category function category_post_count( $atts ) { $atts = shortcode_atts( array( ‘category’ => null ), $atts ); // get the category by slug. … Read more

WP_Query that targets all categories

It’s hard to say exactly why adding the category changes anything, but… The query looks OK… Almost… There are some things that concerns me: ‘post_type’ => ‘posts’, – there is no built-in post type called posts. You should use post in there, unless it’s your CPT (but then… I don’t think it’s a good name … Read more