Custom Post Type as Pick Column

3

How to do we connect a pod to a custom post type in Wordpress 3.0?

Right now the closest thing in the drop down is WP Posts, but that doesn't show posts from custom post types.

asked May 23 '10 at 4:55

Frank Anthony

16

add comment
enter at least 15 characters

18 Answers

1

Hey, no problem. I'm always chasing geese. I should actually change my title to "Professional Goose Chaser" instead of Web Designer :)

answered Jul 14 '10 at 11:21

jonahcoyote

18

add comment
enter at least 15 characters
0

After looking around, I'm assuming this is not currently possible.

Hopefully custom post types will be added as a pick column before the final release of WP3.0

http://podscms.org/codex/pick_column

answered May 25 '10 at 3:32

Frank Anthony

16

add comment
enter at least 15 characters
0

It could be done, but you'd have to hack the pod.class.php file.

answered May 25 '10 at 4:04

Mike Van Winkle

219

add comment
enter at least 15 characters
0

Thanks for commenting.

Looking at http://code.google.com/p/wp-pods/source/browse/trunk/core/Pod.class.php I see the following lines mention wp_posts. Is there anywhere else I should be looking?

Lines 138-145

      // Get datatype ID for non-WP PICK columns
      if (
           !empty($pickval) &&
           !in_array($pickval, array('wp_taxonomy', 'wp_post', 'wp_page', 'wp_user')))
      {
         $result = pod_query("SELECT id FROM @wp_pod_types WHERE name = '$pickval' LIMIT 1");
         $datatype_id = mysql_result($result, 0);
      }

Lines 254-258

    // WP page, post, or attachment
    elseif ('wp_page' == $table || 'wp_post' == $table || 'file' == $table)
    {
        $result = pod_query("SELECT * FROM @wp_posts WHERE ID IN ($tbl_row_ids) $orderby");
    }

Lines 372-383

    // WP page or post dropdown
    elseif ('wp_page' == $table || 'wp_post' == $table)
    {
        $post_type = substr($table, 3);
        $where = (false !== $unique_vals) ? "AND id NOT IN ($unique_vals)" : '';
        if (!empty($pick_filter))
        {
            $where .= " AND $pick_filter";
        }

        $sql = "SELECT ID as id, post_title AS name FROM @wp_posts WHERE post_type = '$post_type' $where ORDER BY $orderby";
    }

Lines 538-546

        elseif ('wp_page' == $table || 'wp_post' == $table)
        {
            $join .= "
            LEFT JOIN
                @wp_pod_rel r$i ON r$i.field_id = $field_id AND r$i.pod_id = p.id
            LEFT JOIN
                @wp_posts `$field_name` ON `$field_name`.ID = r$i.tbl_row_id
            ";
        }

answered May 27 '10 at 3:01

Frank Anthony

16

edited May 28 '10 at 10:59

add comment
enter at least 15 characters
0

Can anyone tell me if this is something I can expect to work with Wordpress 3.0 custom posts in the near future?

I need to make a decision soon on whether to continue with pods for a specific project that uses custom posts.

Thanks for any information you can share.

answered Jun 9 '10 at 11:23

Frank Anthony

16

add comment
enter at least 15 characters
0

Hi Guys

What is the status of custom post type support for PICK columns?

answered Jun 21 '10 at 2:35

Rhys L. Bartels-Waller

35

add comment
enter at least 15 characters
0

Hi all,

I figured out how to pull in posts from a specific post_type but I don't know how to do it dynamically, i.e. for any custom post types created without having to go back and edit Pod.php

Here is what I did:

  1. Get the name of your custom post_type in the wp_posts table - just find a post for that post_type and in the post_type column should read the name.
  2. Open up pods > classes > Pod.php
  3. Go to line 339 and comment out:

    $sql = "SELECT ID as id, post_title AS name FROM @wp_posts WHERE post_type = '$post_type' $where ORDER BY $orderby";

  4. Copy and paste that same line on the next line and change the WHERE clause to:

$sql = "SELECT ID as id, post_title AS name FROM @wp_posts WHERE post_type = '$post_type' || post_type = 'YOUR_CUSTOM_POST_TYPE_NAME' $where ORDER BY $orderby";

Then save and that should show your custom post type posts in the pick drop down.

Now, obviously this workaround sucks because you should never modify core code like this. Anyone have any better ideas?

  • Jonah

answered Jul 13 '10 at 10:38

jonahcoyote

18

add comment
enter at least 15 characters
0

Couldn't you extend the Pod class in your theme's functions.php file and redefine the get_dropdown_values function? You may have to update it if the core changes, but at least you wouldn't be editing core files directly.

answered Jul 14 '10 at 9:51

jackson

33

add comment
enter at least 15 characters
0

That's a good suggestion jackson and I'd like to do that instead of hacking core files, but how would I do it? Filter get_dropdown_values?

answered Jul 14 '10 at 3:54

jonahcoyote

18

add comment
enter at least 15 characters
0

I may have mispoke... since the instance of the Pods class is being created by the core files, you'd have to still edit the core to use the extended class instead of the original.

So, I believe you'd have to use runkit - http://www.php.net/manual/en/function.runkit-function-redefine.php - to redefine the function in this scenario.

I had in my mind a recent project where I had to redefine the list filters, but that was easy since I'm creating the instance of the class in the template code, and as such can modify it to use my extended class.

Hope that helps

answered Jul 14 '10 at 5:46

jackson

33

add comment
enter at least 15 characters
0

Thanks jackson, I tried runkit but I'm not sure how to redefine the function. Would I redefine just the get_dropdown_values function? I tried this where I assigned my modified function to a new variable ($my_function):

runkit_function_redefine('get_dropdown_values', '', $my_function);

But this doesn't work. I'm guessing I need to redefine more than just the get_dropdown_values...

I'm really more of a copy and paste coder though so forgive my ignorance.

  • Jonah

answered Jul 14 '10 at 6:04

jonahcoyote

18

add comment
enter at least 15 characters
0

I'd start with this, to see if you have runkit available:

<?php
if (function_exists('runkit_function_redefine')) {
    echo "runkit_function_redefine available.<br />\n";
} else {
    echo "runkit_function_redefine not available.<br />\n";
} ?>

I'd be remiss not to mention that I have just a little experience with this function : P

Your $my_function variable to be clear, shouldn't include opening and closing <?php ?> tags.

When you say "it doesn't" work - what do you mean? Errors?

Let us know how it goes.

answered Jul 14 '10 at 7:23

jackson

33

add comment
enter at least 15 characters
0

Looks like I don't have runkit available. I get the error:

Fatal error: Call to undefined function runkit_function_redefine()

I tried turning it on but this doesn't work either. Oh well, I'm going to stick with the hacked core file for now until someone suggests something else.

Thanks though, Jonah

answered Jul 14 '10 at 8:02

jonahcoyote

18

add comment
enter at least 15 characters
0

Bummer, sorry for putting you on to a goose chase!

answered Jul 14 '10 at 10:47

jackson

33

add comment
enter at least 15 characters
0

Still no solution or help/comment'/word from the developer on this?

Incredibly frustrating.

answered Jul 25 '10 at 6:53

Frank Anthony

16

add comment
enter at least 15 characters
0

Hey all,

I have kind of a hacky solution to this, but at least it doesn't involve altering the core.

In your PICK Filter for the column, put this:

1=1 OR post_type='your_custom_post_type_name'

That won't filter out posts of type 'post' but at least it's better than not having your custom post types as options at all. I hope this helps someone.

answered Apr 8 '11 at 7:08

cletustboone

1

edited Apr 8 '11 at 7:08

add comment
enter at least 15 characters
0

Pods 2.0 has CPT pick support built in (along with many other additions).

answered Apr 8 '11 at 7:25

sc0ttkclark

2936

add comment
enter at least 15 characters
0

Well For "cletustboone" fix was working but i wanted specific posts in the pick. So here is what i did witch involved hacking the pod core only slightly (I know hacking core is unconscionable but it has to be done to get this right till pods 2.0 roles around but its rather simple) :

<b><u>In pods/classes/Pod.php on line 689:</u></b>

$where .= " AND $pick_filter";

becomes

$where .= "$pick_filter";

<b><u>In pods/classes/Pod.php on line 695:</u></b>

$sql = "SELECT ID as id, post_title AS name FROM $wpdb->posts WHERE post_type = '$post_type' $where ORDER BY $orderby";

becomes

$sql = "SELECT ID as id, post_title AS name FROM $wpdb->posts WHERE $where ORDER BY $orderby";

This removes the where clause in the sql totally. The only caveat is that you have to fill in the "PICK Filter" in the "Edit Column" for your pick field no matter what.

<b><u>To get your normal posts use the following in your pick filter:</u></b>

post_type='post'

<b><u>To get your custom post type use the following in your pick filter:</u></b>

post_type='your_custom_post_type_name'

<b><u>To get your custom post type and regular posts use the following in your pick filter:</u></b>

post_type='your_custom_post_type_name' AND 1=1 OR post_type='post'

<b>Hope this helps someone as it helped me.</b>

answered Apr 15 '11 at 8:20

onfire60

11

edited Apr 15 '11 at 8:37

add comment
enter at least 15 characters