Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to modify WordPress so that it requests content from a function if content is not found in the database.

I want to edit the section of the code which requests and returns the post content from the database so that: if it does not find the content in the database, it calls and gets the content from my function, instead of returning null/not found. I am not sure where this section of the code is or how to go about changing it.

I can write a set of functions which return the title/body/excerpt/tags/etc... when give the post id not found in the database. Please help me in finding who/where to make this edit.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Possibly the place to do this would be in the 404.php file of your theme. If there isn't one, create one and Wordpress will pick up. Note: if you want to return "non-404" content from this file you will probably need to clear the headers and set the status to 200.

I've done something very similar on other systems and it works fine if you take care to return the correct headers.

One word of warning though: you might want to minimise the amount of processing that happens on the this page as otherwise you might end up impacting site performance if you start lots of processing on every single 404.

share|improve this answer
    
That would work, but I want to implement in such a way that the rest of the wordpress code treats it as a regular post. I was thinking that I could just change the part that reads the posts from the database. I would imagine that there are functions like: getPostFromID($postID), getPostFromTitle($postTitle).. that query the database and return the "post object." I would prefer to just change these functions so that, as far as the the rest of code is concerned, it is being taken from the database. What I am trying/hoping to do is to "encapsulate" the database from the rest of the WordPress code –  Bilal Shahid Dec 7 '11 at 6:51
    
I don't know wordpress well enough to say if this is possible, but my guess this you will run into all sorts of problems. A "post" is like the fundamental object in Wordpress and for a given Post it expects there to be an item in the database. –  ZweiBlumen Dec 7 '11 at 7:37
    
Having thought about this, you might want to look into Custom Post types. This will ensure that the post IS in the database, but will give you hooks into how the post is retrieved and processed for that specific type of post only. –  ZweiBlumen Dec 7 '11 at 8:12
    
I am looking at Custom Post types now, and it looks promising. Thanks for the help. –  Bilal Shahid Dec 7 '11 at 8:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.