Closed coding-panda closed 5 years ago
Issue-Label Bot is automatically applying the label Type: Bug
to this issue, with a confidence of 0.99. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!
Links: app homepage, dashboard and code for this bot.
@coding-panda Using the method id()
instead of the parameter fixes your issue.
However @sc0ttkclark, it looks like the fetch()
, reset()
methods etc. don't set the $id
parameter in the Pods
object at all. Might be a good idea to add the following to these methods before returning a value:
$this->id = $this->id()
Let me know and I'll create a PR.
$this->id
only gets set when pods() is intentionally called from a singular context via pods( 'pod_name', $id_or_slug )
or when calling $pod->fetch( $id_or_slug )
. It does not store the current ID when in a fetch()
loop etc. No PR necessary here, but in the future we may expand the Pods
object to support context in a separate class property instead of relying solely on $this->id
internally to track singular versus list.
$this->id
only gets set when pods() is intentionally called from a singular context viapods( 'pod_name', $id_or_slug )
or when calling$pod->fetch( $id_or_slug )
@sc0ttkclark Not entirely correct. $pod->fetch( $id )
does not set the id
parameter. The REST handler uses fetch()
.
Yeah sorry, I should have left the fetch()
part out there, it gets setup by PodsData::__construct()
which is only setup when you do the initial pods( 'pod_name', $id_or_slug )
.
Okidoki, closing this issue then!
Describe the bug When using the filter 'pods_pods_field' on normal pages, the four parameter $instance (object|Pods) (referred to here: http://hookr.io/filters/pods_pods_field/) will pass in the correct id, but with REST API, it seems to pass in the last available id only.
To Reproduce Steps to reproduce the behavior:
Add the following code to functions.php. This function will return the ids from the second and the fourth parameters instead of the value so we can see the error add_filter( 'pods_pods_field', 'pods_field_fn', 10, 4 );
function pods_field_fn( $value_ukn, $row_arr, $params_arr, $pods_obj ){ //print_r($params_arr->name); if( $params_arr->name == 'post_id' ){ return $pods_obj->id; } if( $params_arr->name == 'row_id' ){ return $row_arr['ID']; }
return $value_ukn; }
Expected behavior In REST API, pods_pods_field should receive the correct current Pods object.
Screenshots http://www.codingpanda.co.uk/pprf/wp-json/wp/v2/section/
Pods Version
Please provide the version of Pods you are running: 2.7.12
WordPress Environment
Pods Package Export (helpful!)
{"meta":{"version":"2.7.12","build":1558724616},"pods":{"120":{"id":120,"name":"section","label":"Sections","description":"","type":"post_type","storage":"table","object":"","alias":"","fields":{"post_id":{"id":132,"name":"post_id","label":"Post ID","description":"","help":"","class":"","type":"number","weight":0,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","number_format_type":"number","number_format":"i18n","number_decimals":"0","number_format_soft":"0","number_step":"1","number_min":"0","number_max":"100","number_max_length":"12","oembed_enabled_providers_funnyordiecom":"0","oembed_enabled_providers_photobucketcom":"0","oembed_enabled_providers_polldaddycom":"0","pick_post_status":["publish"],"pandarepeaterfield_table":"member","pandarepeaterfield_field_width":"100","pandarepeaterfield_entry_limit":"0","pandarepeaterfield_enable_load_more":"0","pandarepeaterfield_initial_amount":"10","pandarepeaterfield_enable_trash":"0","pandarepeaterfield_order_by":"pandarf_order","pandarepeaterfield_order":"ASC","pandarepeaterfield_display_order_info":"0","pandarepeaterfield_apply_admin_columns":"0","pandarepeaterfield_allow_reassign":"0","pandarepeaterfield_public_access":"0","subscriber":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"1","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","number_repeatable":"0","number_placeholder":""},"row_id":{"id":133,"name":"row_id","label":"Row ID","description":"","help":"","class":"","type":"number","weight":1,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","number_format_type":"number","number_format":"i18n","number_decimals":"0","number_format_soft":"0","number_step":"1","number_min":"0","number_max":"100","number_max_length":"12","oembed_enabled_providers_funnyordiecom":"0","oembed_enabled_providers_photobucketcom":"0","oembed_enabled_providers_polldaddycom":"0","pick_post_status":["publish"],"pandarepeaterfield_table":"member","pandarepeaterfield_field_width":"100","pandarepeaterfield_entry_limit":"0","pandarepeaterfield_enable_load_more":"0","pandarepeaterfield_initial_amount":"10","pandarepeaterfield_enable_trash":"0","pandarepeaterfield_order_by":"pandarf_order","pandarepeaterfield_order":"ASC","pandarepeaterfield_display_order_info":"0","pandarepeaterfield_apply_admin_columns":"0","pandarepeaterfield_allow_reassign":"0","pandarepeaterfield_public_access":"0","subscriber":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"1","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","number_repeatable":"0","number_placeholder":""},"sectionid":{"id":121,"name":"sectionid","label":"SectionID","description":"","help":"","class":"","type":"text","weight":2,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","oembed_enabled_providers_funnyordiecom":"0","oembed_enabled_providers_photobucketcom":"0","oembed_enabled_providers_polldaddycom":"0","pick_post_status":["publish"],"pandarepeaterfield_table":"member","pandarepeaterfield_field_width":"100","pandarepeaterfield_entry_limit":"0","pandarepeaterfield_enable_load_more":"0","pandarepeaterfield_initial_amount":"10","pandarepeaterfield_enable_trash":"0","pandarepeaterfield_order_by":"pandarf_order","pandarepeaterfield_order":"ASC","pandarepeaterfield_display_order_info":"0","pandarepeaterfield_apply_admin_columns":"0","pandarepeaterfield_allow_reassign":"0","pandarepeaterfield_public_access":"0","subscriber":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","text_repeatable":"0","text_placeholder":""},"description":{"id":122,"name":"description","label":"description","description":"","help":"","class":"","type":"text","weight":3,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","oembed_enabled_providers_funnyordiecom":"0","oembed_enabled_providers_photobucketcom":"0","oembed_enabled_providers_polldaddycom":"0","pick_post_status":["publish"],"pandarepeaterfield_table":"member","pandarepeaterfield_field_width":"100","pandarepeaterfield_entry_limit":"0","pandarepeaterfield_enable_load_more":"0","pandarepeaterfield_initial_amount":"10","pandarepeaterfield_enable_trash":"0","pandarepeaterfield_order_by":"pandarf_order","pandarepeaterfield_order":"ASC","pandarepeaterfield_display_order_info":"0","pandarepeaterfield_apply_admin_columns":"0","pandarepeaterfield_allow_reassign":"0","pandarepeaterfield_public_access":"0","subscriber":"0","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","text_repeatable":"0","text_placeholder":""}},"show_in_menu":"1","label_singular":"Section","public":"1","show_ui":"1","supports_title":"1","supports_editor":"1","publicly_queryable":"1","exclude_from_search":"0","capability_type":"post","capability_type_custom":"section","capability_type_extra":"1","has_archive":"0","hierarchical":"0","rewrite":"1","rewrite_with_front":"1","rewrite_feeds":"0","rewrite_pages":"1","query_var":"1","can_export":"1","default_status":"draft","supports_author":"0","supports_thumbnail":"0","supports_excerpt":"0","supports_trackbacks":"0","supports_custom_fields":"0","supports_comments":"0","supports_revisions":"0","supports_page_attributes":"0","supports_post_formats":"0","built_in_taxonomies_category":"0","built_in_taxonomies_link_category":"0","built_in_taxonomies_post_tag":"0","show_in_nav_menus":"1","show_in_admin_bar":"1","pfat_enable":"0","pfat_run_outside_loop":"0","pfat_append_single":"append","pfat_filter_single":"the_content","pfat_append_archive":"append","pfat_filter_archive":"the_content","rest_enable":"1","rest_base":"section","read_all":"0","write_all":"0"}}}
Additional context Add any other context about the problem here.
Possible Workaround If you have discovered a workaround, please include it below.