url rewriting for custom post types

Yes you can use the rewrite parameter when creating your custom post type: register_post_type( ‘example_type’, array( ‘labels’ => array( ‘name’ => “Example-Type”, ‘singular_name’ => “example-type” ), ‘public’ => true, ‘has_archive’ => true, ‘rewrite’ => array(‘slug’ => ‘the-url-you-want’, ) ); } You will need to reset your permalinks for it to take effect as well. EDIT: … Read more

URL Rewrite – Page Archive

You need to add following two functions in theme functions.php or in a plugin’s php file function func_rewrites_init(){ add_rewrite_rule( ‘programme/(\d+)/(\d+)/?$’, ‘index.php?pagename=programme&pmonth=$matches[1]&pdate=$matches[2]’, ‘top’ ); } add_action(‘init’, ‘func_rewrites_init’); function func_query_vars( $query_vars ){ $query_vars[] = ‘pmonth’; $query_vars[] = ‘pdate’; return $query_vars; } add_filter( ‘query_vars’, ‘func_query_vars’ ); pagename value in the above code have to be according to template … Read more

Problems with custom post type

In your $args array, add ‘show_in_rest’ => true,. This will enable the REST API integration. As for your URLs, you need to flush the rewrite rules. Normally you would want to put your custom post type/taxonomy definitions into a plugin so it is separate from your theme since it deals with content creation/structure as opposed … Read more

Separate Content from gallery (custom post type)

You can do something like this <?php get_header(); ?> <section id=”content”> <div class=”container”> <?php get_template_part(‘inc/page-title’); ?> <div class=”row”> <?php if (have_posts()) : ?> <?php /* Start the Loop */ ?> <?php while (have_posts()) : the_post(); ?> <div class=”col-sm-7 post-thumb large-thumbnail”> <?php the_post_thumbnail(‘model-full’, array( ‘class’ => “img-responsive” )); ?> </div> <div class=”col-sm-5 entry-content profile”> <?php $properties … Read more

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