Modify the category post counting function

When registering a custom taxonomy, register_taxonomy() accepts an update_count_callback argument. This callback function will be called when the count is updated. The default callback is _update_post_term_count() for taxonomies attached to post types, which confirms that the objects are published before counting them. _update_generic_term_count() is the default for taxonomies attached to other object types, such as … Read more

Place a button besides “add new”

The ‘proper’ way would be to use add_action() See: https://codex.wordpress.org/Plugin_API/Action_Reference The closest hook for your need would be ‘edit_form_top’ You could do something like this function add_your_button(){ echo ‘<a href=”https://wordpress.stackexchange.com/questions/294025/index.php?param=your-action” class=”page-title-action”>List View</a>’; } add_action(‘edit_form_top’, ‘add_your_button’); That would achieve: The catch is that there is a hr tag after the Add New so your new button … Read more

How to create a permalink structure with custom taxonomies and custom post types

I suspect the extra slash is coming from the str_replace action because normally there’s no need to manually add slashes when retrieving TAX urls. Since you now end up with 1 unwanted slash, I would recommend testing situations with/without the slash. Starting with removing the one in the function definition. Make it empty, see what … Read more

Create a Hierarchical List of Custom Taxonomies AND Posts

I’ve been working on a solution this afternoon and have come up with the following. It may not be the most elegant way of doing this though, so I’m open to further comments. function custom_tax_list_and_posts() { $post_type=”CUSTOM_POST_TYPE_NAME”; $taxonomy = ‘CUSTOM_TAXONOMY_NAME’; // Get all of the parent terms in the custom taxonomy and include empty ones … Read more

sorting in wp query based on custom field value

“’orderby’ => $company_name,” should be “’orderby’ => ‘meta_value’,“ If the value of _company_name is numeric – it should be meta_value_num. Note that ‘orderby’ can only have a predefined value and ordering does it alphabetical See the possible values at the WP_Query orderby parameter: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters The ordering parameter says: Order alphabetical by the values of meta_key … Read more

Counting the number of post without custom post type

One way to do it would be to run two custom queries like this: $normal_post_args = array( ‘post_type’ => ‘post’, ‘category_name’ => ‘hobby’ ); $normal_posts_query = new WP_Query( $normal_post_args ); $movie_post_args = array( ‘post_type’ => ‘movie’, ‘category_name’ => ‘hobby’ ); $movie_posts_query = new WP_Query( $movie_post_args ); echo “Posts (” . $normal_posts_query->found_posts . “)”; echo “Movies … Read more