پیوند یکتای سفارشی برای محصولات ووکامرس

[short_link]
 
 add_filter('post_type_link', 'product_type_permalink', 10, 4);
function product_type_permalink($post_link, $post, $leavename, $sample) {
    //If is custom post type "product"
    if ($post->post_type == 'product') {
        // Get current post object
        global $post;
        $post_id=$post->ID;

$term_obj_list = get_the_terms( $post_id, 'city_categories' );
$ad_city=$term_obj_list[0]->slug;


 $p_cat = get_the_terms( $post_id, 'product_cat' );
$ad_cat=$p_cat[0]->slug;

         $permalink = get_bloginfo('url').'/'.$ad_city.'/'.$ad_cat.'/'.$post_id;
 
         
    }
    return $permalink;
}
 
 add_action( 'init', 'wpse33551_rewrites_init' );

function wpse33551_rewrites_init(){
      add_rewrite_rule(
          '([^/]+)/([^/]+)/([0-9]+)?$',
        'index.php?post_type=product&p=$matches[3]',
        'top');
}


(0) دیدگاه برای این پست ثبت شده
دیدگاه خود را بفرستید
  1. اولین نفری باشید که دیدگاه خود را ثبت می کند!
« قالب برگه سفارشی در پلاگین تصویر قالب برگه سفارشی در پلاگین
اعتبارسنجی کدملی با استفاده از php »
Clicky