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 am working on a custom job board for a client that wants to deploy this job board on a multi-site network. Here is my problem, I need to store certain jobs in a table that would be accessible to all sites in the network (e.g. a nationwide listing) instead of just locally (e.g. local listing).

My question: can data from a custom post type be stored in a custom table?

Edit: Perhaps more clarification is needed. My client has a multi-site network job board. There are job boards for specific regions (e.g. San Diego, Austin, Denver, etc.). Right now, a user posts a job for Denver on the Denver site but if he has a job he wants to advertise nationwide, he would have to post the job on all sites in the network. We want to create a custom post type for jobs that gives the user the opportunity to select a nationwide category and upon saving the job, have it show up on all the sites in the network. The one way we could see making this work would be to have a job tagged as 'nationwide" save its data in a separate table outside the typical wp_1_posts table so that we could query that table for nationwide jobs and list them on ALL the sites in the network automatically as a part of the theme.

share|improve this question
    
So you mean that you need to display posts from certain blog on your all/some of the other multisite blogs? If yes, then you don't really need to store your posts in a separate table. All you need is a custom query on your other blogs that will query posts from current blog and as well as from that particular blog which has network wide listing. –  Hameedullah Khan May 14 '11 at 17:52
    
If we query posts from the other blogs, each time we add a new site we will have to rewrite the query won't we? –  James H May 14 '11 at 18:38
    
Then you can write a query that will select from all blogs all the posts that are being tagged network wide + the posts of current blog. You won't have to rewrite your query for every new blog, the same query will work on all blogs and it won't matter on which blog the user has posted a nation wide job it will show up on all blogs. If you need example I wrote such a query soem time back, I will post it here lets see what others has to say about it. –  Hameedullah Khan May 14 '11 at 19:22

2 Answers 2

I don't see any reason why you should not stay with a regular custom post type, that is how the data is stored in the database, and it works for multi-site. If you have a particular reason to make a custom database table that I have missed, look at pods cms, this is exactly what it does, or you can always interact directly with the db.

http://podscms.org/
http://codex.wordpress.org/Function_Reference/wpdb_Class

share|improve this answer
2  
I agree with sticking to the baked in custom post types. I've had experience migrating data from an enterprise site away from Pods and it's truly a nightmare scenario. –  Brian Fegter Sep 14 '11 at 6:06

You certainly can save the data however you choose using the save_post action. Simply, place this in your functions.php file.

add_action('save_post', 'foo_save_custom_post_type');
function foo_save_custom_post_type(){
    //Use the following debug code to see what information is available to you
    /*
    echo "<pre>";
    print_r($_REQUEST);
    echo "</pre>";
    exit;
    */

    if('custom_post_type' === $_REQUEST['post_type']){
        //Do your custom table bidding here
    }
}

Make sure you isolate this to your custom post type as this action runs on all post types (i.e. pages, posts, other cpts). Not isolating your operation can get very very expensive on your system resources.

share|improve this answer

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.