is there any way for the display list to only show the book of the post that is currently displayed?
Because there is a relationship between the item and book, I assume what you mean you want the item form to always have the current book selected with no other options.
The below code assumes the name of the relationship field on item
is book
. Since the current book will be selected, there is also an action that hides that form entry.
If displaying the form with an alternative label for the book is preferable, one would remove the action on wp_head
and instead modify $label
with a new label for the book.
It’s worth noting that this will create a new item related to the book for every form entry.
// Only run this on the frontend.
add_action(
'template_redirect',
function(){
/**
* Filter the data of the Items form to only display display the current book.
*
* @see https://github.com/pods-framework/pods/blob/a20d6392eea3cc1fa181953e215cc1c262b15100/classes/fields/pick.php#L2117
* @see https://github.com/pods-framework/pods/blob/a20d6392eea3cc1fa181953e215cc1c262b15100/classes/fields/pick.php#L3110
*/
add_filter(
'pods_field_pick_data',
function( $data, $name, $value, $options, $pod, $id ) {
// Only apply this to the "book" field.
if ( 'pods_field_book' !== $name ) {
return $data;
}
$newdata = [];
foreach( $data as $id => $label ) {
if ( $id === get_the_ID() ) {
// Create a new array which only contains the current book.
// If an alternate label is desired, that could be edited here.
$newdata[ $id ] = $label;
break;
}
}
return $newdata;
},
10,
6
);
// Hide the Book field on "book" posts.
if ( is_singular( 'book' ) ) {
add_action(
'wp_head',
function(){
?>
<style>
label.pods-form-ui-label-pods-field-book, #pods-form-ui-pods-field-book { display:none; }
</style>
<?php
}
);
}
}
);
-
This reply was modified 1 year, 3 months ago by Paul Clark.