"how to create post link in wordpress" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "how to create post link in wordpress" answered properly. Developers are finding an appropriate answer about how to create post link in wordpress related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like how to create post link in wordpress. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on how to create post link in wordpress.
how to create post link in wordpress
add_filter( 'post_type_link', 'wpa_course_post_link', 10, 2 );
add_action( 'pre_get_posts', 'na_parse_request' );
you should first of all costomize in 'wpa_course_post_link' when they are
then u should check if the client ask for page for recegnizing the page
by 'na_parse_request'
// this is example
function __getAllParentsCat($post) {
$category = get_the_category($post);
if(!isset($category[0])) return array();
//firstly, load data for your child category
$child = get_category($category[0]->term_id);
//from your child category, grab parent ID
$cats = array($category[0]->name);
while($parent = $child->parent) {
//load object for parent category
$child = get_category($parent);
var_dump($child->name);
array_push($cats,$child->name);
}
$cats = array_reverse($cats);
return $cats;
}
function wpa_course_post_link( $post_link, $post = 0 ){
if ( 'mq_product' != $post->post_type || 'publish' != $post->post_status ) {
return $post_link;
}
$terms = wp_get_object_terms( $post->ID, 'course' );
$cats = __getAllParentsCat($post);
if ( is_object( $post ) ){
$terms = implode("/",$cats);
if( !$terms ){
$terms = "uncategorized";
}
$post_link = str_replace( '%category%' , $terms , $post_link );
$len = strlen('%post_id%');
$postPos = strpos($post_link,'%post_id%',0);
$post_link_len = $postPos!==false? $postPos+$len:strlen($post_link);
$post_link = substr($post_link,0,$post_link_len);
$post_link = str_replace( '%post_id%' , $post->ID , $post_link );
}
return $post_link;
}
add_filter( 'post_type_link', 'wpa_course_post_link', 10, 2 );
function na_parse_request( $query ) {
$pp = get_post($query->query["p"]);
if (!$pp|| 'mq_product' != $pp->post_type) {
return;
}
$query->set( 'post_type', array( 'post', 'mq_product', 'page' ) );
}
add_action( 'pre_get_posts', 'na_parse_request' );
All those coders who are working on the Whatever based application and are stuck on how to create post link in wordpress can get a collection of related answers to their query. Programmers need to enter their query on how to create post link in wordpress related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about how to create post link in wordpress for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of how to create post link in wordpress while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "how to create post link in wordpress". Visit this developer's friendly online web community, CodeProZone, and get your queries like how to create post link in wordpress resolved professionally and stay updated to the latest Whatever updates.