Query/list all terms and their custom post count

If the taxonomies in question are used ONLY in the post_type in question, then the following simple function will do what you need: function count_term_use ($post_type) { $args = array ( ‘taxonomy’ => get_object_taxonomies ($post_type, ‘names’), ) ; foreach (get_terms ($args) as $term) { echo “$term->name – $term->count\n” ; } return ; } However, if … Read more

Warning: sizeof (): Parameter must be an array or an object that implements Countable, On products pages

Let’s take a look at get_the_terms Codex page. We can find there that this function may return: (array|false|WP_Error) Array of WP_Term objects on success, false if there are no terms or the post does not exist, WP_Error on failure. So your code will work correct only in one case – when the function returns an … Read more

Adding country tags automatically

I’d recommend making use of this API: https://www.countryflags.io/. You’ll also need a list of countries and country codes. Download that here: https://gist.github.com/keeguon/2310008 Then, you can do something like this to register all of the countries to your custom post type’s taxonomy. (you only really need to run this code once) $countries_json = file_get_contents(‘/countries.json/’); $countries = … Read more

WordPress count child posts of each parent custom post type and use in json array for google maps jquery plugin

First of all you should alway separate php from javascript. Generally talking, it’s a bad practise mix them, and specifically to WordPress, it also force you to add javascript inline instead using the WordPress proper way: using wp_enqueue_script. When you need pass variables from PHP to javascript, the proper WordPress way to do it is … Read more

How to hide first gallery for every post?

You could use preg_replace() but I think it’s much easier to overwrite the $output via the post_gallery filter and then remove the filter after the first run: /** * Remove the output of the first gallery * * @param string $output * @param array $attr * @return string $output */ function wpse125903_remove_the_first_gallery( $output, $attr ) … Read more

right_now_content_table_end function not working?

The new action is dashboard_glance_items. It is a filter providing an array to which you can add items. Example from my plugin T5 Taxonomy Location add_filter( ‘dashboard_glance_items’, array ( $this, ‘add_to_glance’ ) ); /** * Add locations to the new “At a glance” dashboard widget. * * @param array $items * @return array */ public … Read more

Count search results in heading

If you check the documentation for WP_Query you will notice that post_count, which you are using, returns the number of posts being displayed. That is what you see, but not what you want. found_posts returns the total number of results for the query, which is what you want. $post_count The number of posts being displayed. … Read more

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