0

I have created a custom user meta = shop_name in User Profile and custom post type gallery

I want my permalink to be in form of /%shop_name%/gallery/%gallery%.

Every user has a custom user_meta = shop_name.

thus if my user has shop_name=shoppers stop and a gallery whose title is Washing Machine then my user url should be http://localhost/shoppers-stop/gallery/mashing-machine

When i go to http://localhost/shoppers-stop/gallery/I want all the galleries of shoppers-stop should be listed. Instead the index page is being shown. How can I make it possible?

Below is the code which i have written.

add_action('init', 'tdd_add_rewrite_rules');
function tdd_add_rewrite_rules(){
// Register custom rewrite rules
global $wp_rewrite;
//$wp_rewrite->add_rewrite_tag('%gallery%', '([^/]+)', 'gallery=');
$wp_rewrite->add_rewrite_tag('%shop_name%', '([^/]+)', 'shop_name=');
 $wp_rewrite->add_permastruct('gallery', '/%shop_name%/gallery/%gallery%', false);
}

add_filter('post_type_link', 'tdd_permalinks', 10, 3); 
function tdd_permalinks($permalink, $post, $leavename){ 
$no_data = get_the_author_meta('ID');;
$post_id = $post->ID;
if($post->post_type != 'gallery' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) return $permalink;
// $var1 = get_post_meta($post_id, 'posts_solicitorspeciality', true);
$var1 = get_the_author_meta('shop_name');

$var1 = sanitize_title($var1);
if(!$var1) { $var1 = $no_data; }
  $permalink = str_replace('%shop_name%', $var1, $permalink); 
  // $permalink = str_replace('%post_id%', $post_id, $permalink); 
return $permalink; 
}
  • What is your question? – Milo Feb 26 '15 at 15:07
  • I have mentioned it – Shahrukh Khan Feb 26 '15 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.