Site icon Hip-Hop Website Design and Development

Customized put up kind permalink tag 404

I am utilizing wp-types to construct a wordpress web site. I am proud of the kinds and their fields, I simply wished to created a perform that reveals mother and father within the url – see blow perform that achieves this – additionally utilizing the Customized Publish Kind Permalinks plugin so as to add my customized tag %mother and father% to the url.

The rewrite appears to work high-quality, shows within the again finish and so forth. However whenever you click on view doc – 404.php.

I’ve tried rewrite flushing – mod rewrite undoubtedly works, as pleasant permalinks work for pages and do not 404, it is solely on the customized put up sorts.

My ultimate url construction is: %sector%/%mother and father%/%postname% – Sector being a customized taxonomy. The customized taxonomy additionally shows high-quality due to the CPTP plugin however 404s as effectively.

wp-types does have rewrite capabilities however they’re all turned off. it is actually bought me stumped, the code under is included in my capabilities.php – I’m utilizing bones starter theme.

Ought to I embrace this code as a plugin as a substitute? Or is there one thing i’ve missed? The one manner I can get entry the gadgets is by setting permalinks to default.

    add_filter('post_type_link', 'parents_post_rewrite_function', 10, 3); 

  perform parents_post_rewrite_function( $post_link, $id = 0, $leavename = FALSE ) {
    $put up = get_post($id);
    $postID = $post->ID;

    // At all times globalize $wpdb
    international $wpdb;

    // Get present posts father or mother kind
    $parentType = $wpdb->get_var("SELECT  `meta_key` FROM  `wp_postmeta` WHERE  `post_id` ={$postID} AND `meta_key` LIKE '%belongs%'");

    // Get present posts parentID if mission
    $parentID = $wpdb->get_var("SELECT  `meta_value` FROM  `wp_postmeta` WHERE  `post_id` ={$postID} AND  `meta_key` =  '{$parentType}'" );

    if(!empty($parentID)){

    // Get father or mother father or mother posts kind
    $parentParentType = $wpdb->get_var("SELECT  `meta_key` FROM  `wp_postmeta` WHERE  `post_id` ={$parentID} AND `meta_key` LIKE '%belongs%'");

    // Try to get similar worth from father or mother ID, if fails then no father or mother of father or mother 
    $parentParentID = $wpdb->get_var("SELECT  `meta_value` FROM  `wp_postmeta` WHERE  `post_id` ={$parentID} AND  `meta_key` =  '{$parentParentType}'" );

    }

    if(!empty($parentParentID)){
            $parentslug = get_post($parentID)->post_name;
            $parentparentslug = get_post($parentParentID)->post_name;
            $mother and father = $parentparentslug.'/'.$parentslug;
    } else {
        $mother and father = get_post($parentID)->post_name;
    }

    // Get mother and father father or mother put up ID & proceed till none discovered
    // Convert IDs to names and render slug

    return str_replace('%mother and father%', $mother and father, $post_link);
  }