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.

8 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

  2. I know this post is practically ancient but I’d like to do just as described on a page I’m working on. At the moment I’m running it in wordpress locally but I want the user to submit more “services along with the price” and have that data be auto-published so that they can use it instantly on the page I’m making available for them. Working on a sort of calculator for their job services. I’m wondering where I would make this modification and if it still works.

    • Hi Juan,

      I can’t say I’ve done much with PODS in a long while but, to the best of my knowledge, this should all still work. Where you make the change depends on your circumstances, but I would generally recommend writing a small plugin to add this code to. You might be tempted to add it to your theme, but really changes to the overall behaviour of your website should be encapsulated in a plugin.

      HTH, Matt.

Leave a Reply

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