how to retain the ability to modify the post slug after applying a post_type_link filter?

One possible solution can be this one: add_filter(‘wp_insert_post_data’, ‘update_post_data’ , 10, 2); function update_post_data($data, $postarr){ if($data[‘post_type’] !== ‘gallery’) return $data; $data[‘post_name’] = wp_unique_post_slug(sanitize_title($data[‘post_title’]), $postarr[‘ID’], $data[‘post_status’], $data[‘post_type’], $data[‘post_parent’]); return $data; } This will auto-update the post slug upon updating the post. It works great as far as it’s ok for you to have the post slug … Read more

Post Name Permalink setup gives 404 error inside sub-directory

It’s happening because Nginx doesn’t interpret rewrite rules like Apache via mod_rewrite. You need to change your nginx vhost config file (nginx site config file, i.e /etc/nginx/sites-enabled/your-site-config.conf file) Add the following line inside server block location / { try_files $uri $uri/ /index.php?$args; } if the location / is already present, then remove the existing try_files … Read more

help to remove last trailing slash using add_rewrite_rule

Replace all your above code with the one below: <?php function master_load_ads_txt_template_include( $template ) { $is_load_ads_txt = (bool) get_query_var( ‘ads-txt’ ); if ( $is_load_ads_txt ) { $template = locate_template( ‘template-parts/ads-txt.php’ ); } return $template; } add_filter( ‘template_include’, ‘master_load_ads_txt_template_include’ ); function master_load_ads_txt_rewrite() { add_rewrite_rule( ‘ads.txt’, ‘index.php?ads-txt=true’, ‘top’ ); // The line below doesn’t work and it’s … Read more

How to get all posts related to particular category name on button click?

How to get category wise all post in WordPress? Add below code in taxonomy-“yourtaxonomyname”.php for ex : file name : taxonomy-event-category.php & Post type : events & taxonomy name : event-category <?php $category_object = get_queried_object(); $category_taxonomy = $category_object->taxonomy; $category_term_id = $category_object->term_id; $category_name = $category_object->name; $category_description = $category_object->description; $category_slug = $category_object->slug; $post_type=”events”; $paged = (get_query_var(‘paged’)) ? … Read more

register_post_type permalink

You have to use post_type_link filter. Create a handler to handle this filter, you can create $permalink as per your need there. In addition to this, you may have to use “pre_get_posts” action also. I used both these couple of months ago, I created permalinks to show as cpt_name/post_name.