1. The custom code used a deprecated function get_currentuserinfo(), which has to be replaced with wp_get_current_user().
2. Then there are notices about wpkses nowadays, using that code:
Notice: Undefined index: input in /Applications/MAMP/htdocs/Stable/wp-includes/kses.php on line 866
3. Even if that error is resolved by changing the Query type, it still won't work with the new Select2.
We have a small issue here, because the Select2 is only triggering on 15+ posts.
Hence, until then we need the old code, but after Select2 Triggers, it shall use a new approach.
I need the Developers to deploy something here, this is not a good solution if we hack this with Custom Code.
For now, I deployed this Solution (not particularly proud if it) for you:
1. Create a View
2. Query your Post Type in question, and add a Query filter as:
Select posts with the author the same as the current logged in user.
3. Add this to the Loop. Pay attention to put it all inline, exactly as I paste it:
[wpv-items-found]<!-- wpv-loop-start --><wpv-loop>[wpv-item index=1]{"value":"[wpv-post-id]","label":"[wpv-post-title]"}[wpv-item index=other],{"value":"[wpv-post-id]","label":"[wpv-post-title]"}</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found]
4. Now in CRED Create a generic Select Field and use the View as the ShortCode to populate it:
[cred_generic_field field='parent_field' type='select' class='' urlparam='']
{
"required":1,
"validate_format":0,
"default":[],
"options":[ [wpv-view name="test"] ]
}
[/cred_generic_field]
5. Finally add this to the Theme's Functions file:
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
function prefix_clean_view_output( $out, $id ) {
if ( $id == '61' ) { //change the ID
$start = strpos( $out, '<!-- wpv-loop-start -->' );
if (
$start !== false
&& strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
) {
$start = $start + strlen( '<!-- wpv-loop-start -->' );
$out = substr( $out , $start );
$end = strrpos( $out, '<!-- wpv-loop-end -->' );
$out = substr( $out, 0, $end );
}
}
return $out;
}
This works fine, I tested this fully.
I will push the feature request to make it possible natively, and for now we can suggest above approach?
I know that this is not nice, it's not suggested to use Views like this as it can have side effects on that filtered View.
But for now, it's the only workaround.