Using Orderby and meta_value to order natural/alphanumerical

The orderby argument is limited by what is possible in MySQL, and it’s not good at natural alphanumeric sorting like you describe. Possible options include: Rewriting the values with leading zeros, e.g. “CA05” Creating a separate “Sort Order” column that just stores an integer, and ordering by that. Separating the letters and numbers into two … 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.

How can I get the last 5 element of this tax query?

add the ‘date_query’ parameter to your query and include the current year. $args = array( ‘post_type’ => ‘news’, ‘posts_per_page’ => 5, ‘post_status’ => ‘publish’, ‘order’ => ‘ASC’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘week’, ‘field’ => ‘slug’, ‘terms’ => date(“W”, strtotime(“this week”)), ) ), ‘date_query’ => array( array( ‘year’ => date(“Y”) ) ) );

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

Widget area for individual posts (custom post type)?

Assuming that your theme still has the_content to populate that area you can use the_content filter to populate is. Because widgets normally echo their output you would also need to buffer output. Like this: add_filter (‘the_content’,’wpse304648_widget_content’); function wpse304648_widget_content ($content) { if (get_post_type == ‘your_cpt_name’) { ob_start (); .. execute widget $content = ob_get_contents(); ob_end_clean(); } … 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