Add nonexisting pages to navigation

I want to include categories which are listed in a non-native WordPress table to display within the “normal” wp page navigation
(the table comes from WP-Filebase and is called ->prefix .wpfb_cats)

I have put the following in my themes function file, which does add the categories into the navigation and in the right hierachical order. However, none of these have any links (I suppose it’s because those pages do not exist as such in the wp_post table )

How can I persuade wp to to recognize these as pages and, when clicked on it, display the content?
Am I using the right hook?
When I echo the WPPost object at the end of that function, these additional pages are in there, but just the title. How can I show links in the navigation?

add_filter('get_pages','msci_wpfb_frontend_menus',10,2);

function msci_wpfb_frontend_menus($pages,$query){

        global $wpdb;
        $wpfbCats=$wpdb->get_results("SELECT * FROM ".$wpdb->wpfilebase_cats." WHERE cat_exclude_browser="0" ", ARRAY_A );
        foreach($wpfbCats as $k=>$v){
            $wpfbId=9999;/*add improbably high id so there are no clashes with any actually existing pages**/
            $id=$wpfbId+$v['cat_id'];

                if($v['cat_parent']==0){
                    $pid=4;/*display the wpfb top categories under this - existing - page*/
                }else{
                    $pid=$wpfbId+$v['cat_parent'];
                }
                $name=$v['cat_name'];

                $page=array(
                    'ID' => $id,
                    'post_author' => $v['cat_owner'],
                    'post_date' => date('Y-m-d H:i:s'),
                    'post_date_gmt' => date('Y-m-d H:i:s'),
                    'post_content' => '####some content####',
                    'post_title' => $v['cat_name'],
                    'post_excerpt' => '',
                    'post_status' => 'publish',
                    'comment_status' => 'closed',
                    'ping_status' => 'closed',
                    'post_password' => '',
                    'post_name' => sanitize_title($v['cat_name']),
                    'to_ping' => '',
                    'pinged' => '',
                    'post_modified' => date('Y-m-d H:i:s'),
                    'post_modified_gmt' => date('Y-m-d H:i:s'),
                    'post_content_filtered' => '',
                    'post_parent' => $pid,
                    'guid' => ''.$id.'', 
                    'menu_order' => $v['cat_order'],
                    'post_type' => 'page',
                    'post_mime_type' => '',
                    'comment_count' => 0,
                    'filter' => 'raw'
                );
                $wpfbCat = new WP_Post ();
                foreach($page as $k=>$v){
                    $wpfbCat->$k=$v;
                }
                $pages[]=$wpfbCat;
    }
    return $pages;
}

1 Answer
1

Try the filter ‘page_link’, and manipulate the url if id is over $wpfbId

http://codex.wordpress.org/Plugin_API/Filter_Reference

applied to the calculated page URL by the get_page_link function.
Filter function arguments: URL, page ID. Note that there is also an
internal filter called _get_page_link that can be used to filter the
URLS of pages that are not designated as the blog’s home page (same
arguments). Note that this only applies to WordPress pages, not posts,
custom post types, or attachments.

Leave a Comment