Support » Plugins » Hacks » Custom plugin with heirarchy of SEF pages

  • Resolved codelizard


    Here’s my issue. My company needs a vendor database added to our wordpress website. None of the existing plugins will even come close to what we need, and we already have a mysql database with all of our information, so we need to create a plugin or something to do what we need.

    These urls need to be direct-accessible and have SEF urls. So, for example:

    And, the custom content needs to appear inside the wordpress template.

    There are really 2 options:

    1) Find a way to write our application outside of wordpress, but find a way to bootstrap wordpress to show the header, footer, and sidebar.

    2) Run the app from inside wordpress.

    So I went for option #2. I created a new template file named “vendor.php”, and began working. I added this code to my functions.php of my theme:

    add_filter( 'template_include', 'xyz_template_check' );
    function xyz_template_check() {
        global $template;
        $rqst = $_SERVER['REQUEST_URI'];
        $ra = split("/", $rqst);
        if ($ra[1] == "vendors") {
            $template_file = get_stylesheet_directory() . '/vendors.php';
            return $template_file;
        return $template;

    So what the above code does, if it sees the word “vendors” as the first part of the url after the site name, it sends you to vendor.php. This works PERFECTLY….


    WordPress believes that the page is not found. It returns a 404 header, and NOT FOUND into the page title and breadcrumb.

    Adding a PAGE called “Vendor Database” with the permalink “/vendors/” fixes the main page. But there will be literally hundreds of vendors and different categories. I cant be creating a custom page for each one. This needs to be dynamic.

    So, how do I make wordpress give a 200, and supply an acceptable page title, breadcrumb, etc.

    Dont even get me started on the danged wp_title filter. This did NOT work as documented. Although, it just occurred to me that this might be an issue with WordPress SEO (the wp_title filter issue).

    Anyone got an idea on this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • So, a thought. Maybe I do have a “page” for each vendor. I could write a batch job to run through the DB and create a page for each entry in my DB, and then write a piece of code to do all of the DB stuff each time I add/edit/delete a record in our main database.

    Besides that, the only other thing I could think of was trying to put all of our data into wordpress as a custom post type, but with all of my requirements I’m sure it would work either.

    Nothing from the experts on this? Even a gentle kick in the right direction?

    Moderator bcworkz


    Why won’t custom post type work? Sounds like the answer to me. A related approach would be using the Rewrite API somehow, it will function like your code but without 404 errors.

    You shouldn’t need a page for every vendor. I would imagine the data you need for each page already exists somewhere. Given the vendor’s name from the permalink, pull in the data and insert it in the appropriates slots on the one page template.

    Ok got this. The solution was to use the rewrite api, as mentioned above, to look for the pattern /vendors/, letting it know that it was a valid URL. Coupled with my existing template override, this is what I needed.

    On a side note, in regards to the custom post type, this data is actually in a completely third-party system utilizing its own database. Doing the code this way, I’m able to leverage the data from the existing system which handles all of the adds, updates, deletes, etc without needing to write a bridge to duplicate the data into the wordpress db and keep them in sync. This is a better solution for our situation…

    oops, forgot to mark it resolved.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom plugin with heirarchy of SEF pages’ is closed to new replies.