google-code-export / wordpress-custom-content-type-manager

Automatically exported from code.google.com/p/wordpress-custom-content-type-manager
2 stars 1 forks source link

Relation custom field should allow selection from private and draft post/custom types (not just published) #459

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The "Relation" custom field is great. It saves so much time! However, unless 
I'm missing something, I'm in a pickle right now as I can't select/search 
within posts that are private or draft. It only allows me to select from the 
ones that are published.

I'm improving a review website where experts first answer a set of questions 
before a review is published. During that time, the review (which is a custom 
post type) is private. I have other post types which have custom fields 
pointing to the reviews (which are private) and I'd very much like to be able 
to select those too.

I'm sure this is trivial to fix (haven't looked at your code yet to hack it 
myself).

Keep up this great work!

Original issue reported on code.google.com by bogdan.a...@gmail.com on 18 Feb 2013 at 12:51

GoogleCodeExporter commented 9 years ago
Seems I can modify the /config/selector/_relation.php file and then add 
'private' to the 'post_status' list which currently only has 'inherit' and 
'publish', i.e.:

CCTM::$post_selector['post_status'] = array('publish','inherit');

It would be nice to modify this on a per-field basis, rather than global ... if 
you implemented that already then hats off to you (in that case, it would be 
nice to add GUI options for them).

Original comment by bogdan.a...@gmail.com on 18 Feb 2013 at 1:30

GoogleCodeExporter commented 9 years ago
Ok, hats off and apologies for wasting your time.

I can indeed create custom config files in the 
/wp-content/upload/cctm/config/post-selector/ folder, named either as 
custom-field-type-name.php or override the core ones like _relation.php and 
modify the 'post_type' list adding 'private' to it.

I guess i should have rtfm in more depth ... i still don't know how much all 
thi sis actually explained in the docs/wiki (I reversed engineered the code to 
figure out all this functionality).

Cheers and congrats for this powerful plugin!

Original comment by bogdan.a...@gmail.com on 18 Feb 2013 at 1:42

GoogleCodeExporter commented 9 years ago
Yeah, really this is a problem of missing documentation.  To do this correctly, 
you should copy the config/search_parameters/_relation.php file to 
wp-content/uploads/cctm/config/search_parameters/_relation.php and then add a 
new line to your copy:

CCTM::$search_by[] = 'post_type';
CCTM::$search_by[] = 'post_status'; // <--- add this line
CCTM::$search_by[] = 'taxonomy';
CCTM::$search_by[] = 'taxonomy_term';
CCTM::$search_by[] = 'post_parent';
CCTM::$search_by[] = 'meta_key';
CCTM::$search_by[] = 'meta_value';

The wiki has this page that should help you: 
http://code.google.com/p/wordpress-custom-content-type-manager/wiki/Config_post_
selector_relation

Apologies if that's not the easiest page to find -- I added a few more links to 
that page and cleaned up some murky descriptions in the wiki and in the code.

Original comment by ever...@fireproofsocks.com on 18 Feb 2013 at 6:45

GoogleCodeExporter commented 9 years ago
Cute, I haven't tried that. The solution I used was to copy _relation.php from 
post_selector into /wp-content/upload/cctm/config/post_selector/_relation.php 
and add 'private' to the list:

CCTM::$post_selector['search_columns'] = array('post_title', 'post_content');
CCTM::$post_selector['post_status'] = array('publish','inherit','private');  // 
<--- this list
CCTM::$post_selector['orderby'] = 'ID';
CCTM::$post_selector['order'] = 'DESC';
CCTM::$post_selector['limit'] = 10;
CCTM::$post_selector['paginate'] = 1; 

which will always display private posts. I see that your solution does the same 
thing and it's actually better (in case more post_type's appear in the future).

Original comment by bogdan.a...@gmail.com on 18 Feb 2013 at 2:20

GoogleCodeExporter commented 9 years ago
Actually, your solution doesn't quite work. While it allows me to search for 
the post_status, I still can't select 'private'. I can only select draft, 
inherit, publish, auto-draft (private is not in the list).

Original comment by bogdan.a...@gmail.com on 18 Feb 2013 at 2:32

GoogleCodeExporter commented 9 years ago
... and the fix for that is to edit GetPostsForm.php and alter the 
_post_status() method replacing

        $post_statuses = array('draft', 'inherit', 'publish', 'auto-draft');

with

        $post_statuses = array('draft', 'inherit', 'publish', 'auto-draft','private');

:)

Original comment by bogdan.a...@gmail.com on 18 Feb 2013 at 2:46

GoogleCodeExporter commented 9 years ago
Ah, good point.  I'll add that to the GetPostsForm class.  Will go out with 
0.9.7.

Original comment by ever...@fireproofsocks.com on 18 Feb 2013 at 3:44

GoogleCodeExporter commented 9 years ago
You may also consider including post_status in the search criteria by default

Original comment by bogdan.a...@gmail.com on 18 Feb 2013 at 10:16

GoogleCodeExporter commented 9 years ago
I see that now post_status is included by default in the search criteria. 
However, it doesn't include all statuses that exist and could be chosen from. 
For instance "pending" is missing, and by default, pending posts are not shown 
so the fact that the post_status is available as search criteria doesn't help 
with pending posts.

Same goes for "future" status. The ones missing are: pending, future, trash

Why not show all statuses?

Original comment by bogdan.a...@gmail.com on 28 Feb 2013 at 9:07

GoogleCodeExporter commented 9 years ago
// it's just a matter of editing GetPostsForm.php again, as I in my post #6 
above

Original comment by bogdan.a...@gmail.com on 28 Feb 2013 at 9:09

GoogleCodeExporter commented 9 years ago
Ok, I can update the class -- I didn't realize there were more, so the ones 
there were born from a SELECT DISTINCT query on the database, not on any WP 
docs.

Edit the line includes/GetPostsForm.php line 888 and append items to the array:

$post_statuses = array('draft', 'inherit', 'publish', 
'auto-draft','private','pending', 'future', 'trash');

Committed revision 674762.

Original comment by ever...@fireproofsocks.com on 28 Feb 2013 at 9:13

GoogleCodeExporter commented 9 years ago
Yes, I've already done the edit (suggested in my post above at #6). The 
possible statuses are listed in the Codex: 

http://codex.wordpress.org/Function_Reference/get_post_status

Possibly in other Codex pages too but I didn't bother. You probably didn't have 
any other post statuses at the time you issues the SELECT DISTINCT.

Original comment by bogdan.a...@gmail.com on 28 Feb 2013 at 9:35

GoogleCodeExporter commented 9 years ago
Better yet, instead of hard-coding them in an array in GetPostsForm, you could 
replace that hard-coded array with the results from a SELECT DISTINCT query 
(who knows what the WP devs or some other Plugin decides to add/alter)

Original comment by bogdan.a...@gmail.com on 3 Mar 2013 at 5:23