Count user posts by user ID, Post type and Post status

Here is a quick solution to get the post count any kind of filtering you want function custom_get_user_posts_count($user_id,$args ); $args[‘author’] = $user; $args[‘fields’] = ‘ids’; $ps = get_posts($args); return count($ps); } Since this function uses get_posts you can filter and use anything that you can with WP_Query So in your case you can use it … Read more

Looping Through Custom Tax Terms and Displaying All Posts For Each

If your things are laid properly, this code will output 10 posts from film CPT, where taxonomy is category-film and it will occur each of the term of that particular taxonomy. I’m not aware about your templating, so lay your layout accordingly. <?php $_terms = get_terms( array(‘category-film’) ); foreach ($_terms as $term) : $term_slug = … Read more

How best to inject ads between posts in the loop?

Probably just add a counter, show ad on multiples of 6. Something like $count = 0; $adEvery = 6; if (have_posts()) : while (have_posts()) : the_post(); // Individual Post $count++; if ($count%$adEvery == 0) { // your ad } endwhile; else : // No Posts Found endif;

add_query_arg() XSS Vulnerability

Unless I’m missing something that is staring me in the face, you aren’t using add_query_arg() or remove_query_arg(); since those are the only functions affected by this particular exploit you should be safe. Your code does use the query_vars filter and get_query_var() but neither of those are effected by the exploit you’ve referenced. Otherwise your code … Read more

Counter code for paginated category pages in wordpress

Yes, of course it starts again at 1. You’ve initialized the counter to 1 on each page load. If you were writing a custom loop you’d do this: $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; If normal WordPress pagination mechanisms are working on your page that should work for you too. That will number your … Read more

Display Post by taxonomy and taxonomy child

You should query all accomodation posts in this country, and then sort them by accomodation-type and region. Then you loop through the posts, and compare the accomodation type and the region of each post with those of the previous post. If they are different you print the new accomodation type or region and then print … Read more

Categories and products in random order

as suggested by kaiser, my last working edit as solution: ok, inspired by @s_ha_dum answer i manged to get a solution: //this 1. part is out of the woocommerce-template.php and part of the woocommerce_product_subcategories() $product_cat = get_term_by( ‘slug’, $product_cat_slug, ‘product_cat’ ); $product_category_parent = $product_cat->term_id; $pcat_args = array( ‘child_of’ => $product_category_parent, ‘hide_empty’ => 1, ‘hierarchical’ => … Read more

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