Setting category for post as default

I just recently did this with a custom post type and custom taxonomy with the following code. function cpt_assign_term($post_id) { $current_post = get_post( $post_id ); // Only apply to new posts. if ( $current_post->post_date == $current_post->post_modified ) { wp_set_object_terms( $post_id, ‘default-term_name-or-id’, ‘category’, true ); } } add_action( ‘save_post_{your-post-type}’, ‘cpt_assign_term’ ); https://codex.wordpress.org/Function_Reference/wp_set_object_terms

Hide category name using mod_rewrite

I solved my problem. All I needed was the WordPress Rewrite API. if( ! function_exists(‘theme_add_rewrite_rules’) ){ function theme_add_rewrite_rules(){ add_rewrite_rule( ‘^blog/([^/]+)/?$’, ‘index.php?name=$matches[1]’, ‘top’ ); } } add_action( ‘init’, ‘theme_add_rewrite_rules’); This solves how wordpress will parse the URL. Half of the problem is how to modify the posts so that the links will not include the /en/ … Read more

Exclude posts with certain tags in category archive

You could modify your query on pre_get_posts. Example: // I’d wouldn’t hardcode the tags/category ids, but where to store and // how to retrieve those settings go beyond the scope of this question. define( ‘YIVIS_EXCLUDED_TAG’, 12 ); add_action( ‘pre_get_posts’, ‘yivi_excludes_tags’ ); function yivi_excludes_tags( $query ) { if ( $query->is_category() { $query->set(‘tag’, [ YIVIS_EXCLUDED_TAG * -1 … Read more

How to Query the Top 5 Posts of a specific category?

Well, depending on what you mean by top 5 posts. You can get top most read, top commented, most liked etc. For comments you can just make your query with argument orderby=comment_count If you want the most viewed, first you need to add the views counter like this: /********* Post Views counter ***********/ remove_action( ‘wp_head’, … Read more

How to auto update post title and slug with category name when post status is updated

You need post status transitions, and quite similar with this post: Detect type of post status transition only what you need to do update post title and slug, and this is easy. Update post examples Since you wrote like this: add_filter( ‘the_title’, ‘my_modify_title’, 10, 2 ); function my_modify_title( $title, $id ) { if( in_category( ‘My … Read more

How Can Hide Define Category in Post Contents?

First add get_the_categories filter before the_category(‘ , ‘) then remove it. So it will not effect categories on other places. add_filter( ‘get_the_categories’, ‘remove_selected_categories’ ); the_category(‘ , ‘); remove_filter( ‘get_the_categories’, ‘remove_selected_categories’ ); In callback function check for categories to remove then remove them! function remove_selected_categories( $categories ) { $categories_to_remove = array( ‘years’, ‘genere’ ); //Place the … Read more

How to display get_categories selected category?

You need to save your selection and then call that selected value into your widget() method. Here is an example of what I mean which displays the selected category name and description in the front end. You can use this widget as a base for your own widget. Just a note, this widget requires at … Read more

Get the categorie name of Event Organiser plugin [closed]

Okay I found the solution. A view in the mySQL table helped to understand how the Event Organiser plugin is using WordPress. The Event Categories a just normal categories with the taxonomy event-category. The only function needed is get_term_by(). // Get term by slug ”test-cat” in event-category taxonomy. $cat = get_term_by(‘slug’, $eo_event_loop->query[‘event-category’], ‘event-category’); echo $cat->name; … Read more