Storing Custom Post Type Data in a Custom Table

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?

Read More

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.

Related posts

Leave a Reply

2 comments

  1. 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.