order posts by a secondary query that counts items

The way to go is apply custom filters to the WP_Query you are running. add_filter(‘posts_clauses’, function ($clauses, $query) { global $wpdb; // only run the filter for a given query // do your checks and return early if (!$query->is_main_query() || !$query->is_post_type_archive(‘tracklist’)) { return $clauses; } $clauses[‘fields’] .= “, COUNT(items.id) AS track_count”; $clauses[‘join’] .= ” LEFT … Read more

Count how many posts have a specified tag AND category

You could use WP_Query and specifically a tax_query: $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => array( ‘allow-list’ ), ), array( ‘taxonomy’ => ‘post_tag’, ‘field’ => ‘slug’, ‘terms’ => array( ‘cats’ ), ), ), ); $the_query = new WP_Query( $args ); if … Read more

How to display total user count by specific role in WordPress as statistics?

insert this code in your theme functions.php and use this shortcode [users_count_bro] to display where you want function total_count_bro() { $out=””; $user_count_data = count_users(); $avail_roles = $user_count_data[‘avail_roles’]; foreach ( $avail_roles as $role_key => $role_count ) { $out .= $role_key.’:’.$role_count.'<br/>’; } return $out; } add_shortcode( ‘users_count_bro’, ‘total_count_bro’ );

php loop error for count posts in category

I have a working solution now… finally! <?php foreach ( $categories as $category ) { // If there is only one post available, go directly to the post if($category->count == 1) { $all_posts = get_posts($category); echo ‘<div class=”item”><h4 class=”item-title”>’ . get_the_title($all_posts[0]->ID) . ‘</h4><a href=”‘ . get_permalink($all_posts[0]->ID) . ‘”>Read more</a></div>’; } else { echo ‘<div class=”item”><h4 … Read more

Like and Dislike Buttons on Post with Counter – Only allow one click per post per user session

Untested Pseudo-code examples, which you can expand to resolve the issues: function get_the_user_ip() { if ( ! empty( $_SERVER[‘HTTP_CLIENT_IP’] ) ) { //check ip from share internet $ip = $_SERVER[‘HTTP_CLIENT_IP’]; } elseif ( ! empty( $_SERVER[‘HTTP_X_FORWARDED_FOR’] ) ) { // to check ip is pass from proxy $ip = $_SERVER[‘HTTP_X_FORWARDED_FOR’]; } else { $ip = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)