Auto-Publish PODS

Auto-publishing of pods is a feature that is currently missing from the PODS framework for WordPress, but is on its way. In the meantime, here’s how to do it yourself.

Here’s a dead simple snippet of code to make your life easier if you use the PODS CMS framework for WordPress, and want to allow users on the front-end to submit content to your site. By default, after submitting a form in the front-end, the pod will be marked as draft in the back-end. You might not want this. If you want to have the pod go straight to published status then here’s what you need:

function sitename_pods_post_save($pieces, $isNewItem) {
if ($isNewItem) {
$params = $pieces['params'];
$pod_id = $params->id;
$post = get_post( $pod_id, 'ARRAY_A' );
$post['post_status'] = 'publish';
wp_update_post($post);
}
}
add_filter('pods_api_post_save_pod_item', 'sitename_pods_post_save', 10, 2);

If you want to output an editable form the code for that is pretty straightforward too:

$pod = new Pod( 'podname' );
echo $pod->form();

You can customise the fields you want to show in the form without too much trouble:

$pod = pods( 'podname' );
echo $pod->form(array(
"field1",
"field2"
));

Hope that helps someone!

About Matt Lowe

Matt Lowe is a WordPress web designer / developer based in Newbury, Berkshire. After 8 years of doing the nine-to-five for other companies and watching them make the same mistakes over and over he set out in business on his own, forming Squelch Design to help businesses get online and make money.

6 comments on “Auto-Publish PODS

  1. Matt-
    This is a very useful post. I;m the community manager for Pods and I’d like to add a link to this post in the tutorials section of Pods.io, but I was hoping that you could make one update to the code to version 2.X syntax first. $pod = new Pod( 'podname' ); should be $pod = pods( 'podname' );.

    Thanks,
    Josh

Leave a Reply

Your email address will not be published. Required fields are marked *