Can’t get values from related post
-
I have two pods: 1).agenda_fietsroutes and 2).fietsroutes. The title of 2). is the built-in title of wordpress and is related to 1). (title for 1). is selected from list of all titles of 2). )
I’m trying to create a php template which displays the routes that are on the calendar for the current week and the next week. I got the code working to select the needed fields from 1).
Now I want the title of 1). to be a link to the related pod 2). which contains several details about the route. I’ve looked at several examples suggested to do this, but I can’t get it to work. Like the example in your tutorials section:https://docs.pods.io/tutorials/get-values-from-a-relationship-field/#more-665
I added a part at the end that echos a messages if $related is empty. And that message gets displayed.
I wonder if the way I have the relationship declared is wrong. I can’t get it to be a bi-directional relationship because it says: no related fields found.
Could you help me with this? You may probably need more info, please let me know what you might need. I can’t give a link since it is a site on localhost.
Thanks in advance,
Bert
-
The code I use in my template:
<?php /* Template Name: wdtv upcoming programm Template Post Type: post, page, fietsroutes, agenda_fietsroutes Description: Template om de komende fietsroutes van het programma weer te geven op de homepages. */ ?> <div class="wdtv_club_titel">Programma aankomende weken:</div> <?php // Get the weeknumber for the current week and the next week $cur_week_nr = date('W'); $nxt_week_nr = ($cur_week_nr + 1); // Set up the parameters for pods::find $params = array( 'where' => 'week.meta_value = "' . $cur_week_nr . '" OR week.meta_value = "' . $nxt_week_nr . '"', 'limit' => -1 ); // Run the find $wdtv_pods = pods( 'agenda_fietsroutes', $params ); if ( $wdtv_pods->total() > 0 ) { while ( $wdtv_pods->fetch() ) { $route = $wdtv_pods->display( 'titel' ); $datum = $wdtv_pods->display( 'datum' ); $tijd_vertrek = $wdtv_pods->display( 'vertrektijd' ); $plaats_vertrek = $wdtv_pods->display( 'vertrekplaats' ); $wdtv_pod = pods( 'agenda_fietsroute', get_the_id() ); $wdtv_releated = $wdtv_pod->field( 'relationship_field' ); if ( !empty ( $wdtv_related ) ) { foreach ( $wdtv_related as $wdtv_rel ) { $wdtv_id = $wdtv_rel[ 'ID' ]; } } ?> <div id="wdtv_programma_container"> <div id="wdtv_programma_item"> Op <?php echo $datum; ?> rijden we de <?php echo '<a href="' . esc_url( get_permalink( $id ) ) . '">' . $route . '</a>'; ?> </div> </div><?php } } else { ?>er staan geen activiteiten gepland voor de komende weken.<?php } ?>
I also exported the two pods:
{“meta”:{“version”:”2.7.23″,”build”:1604347348},”pods”:{“68”:{“id”:68,”name”:”agenda_fietsroutes”,”label”:”Agenda Fietsroutes”,”description”:””,”type”:”post_type”,”storage”:”meta”,”object”:””,”alias”:””,”fields”:{“titel”:{“id”:75,”name”:”titel”,”label”:”Titel”,”description”:”Selecteer de route”,”help”:””,”class”:””,”type”:”pick”,”weight”:0,”pick_object”:”post_type”,”pick_val”:”fietsroute”,”sister_id”:””,”required”:”0″,”oembed_enabled_providers_facebookcom”:”0″,”oembed_enabled_providers_hulucom”:”0″,”oembed_enabled_providers_instagramcom”:”0″,”pick_format_type”:”single”,”pick_format_single”:”dropdown”,”pick_format_multi”:”checkbox”,”pick_display_format_multi”:”default”,”pick_display_format_separator”:”, “,”pick_allow_add_new”:”1″,”pick_taggable”:”0″,”pick_show_icon”:”1″,”pick_show_edit_link”:”1″,”pick_show_view_link”:”1″,”pick_limit”:”0″,”pick_user_role”:[],”pick_post_status”:[“publish”],”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″,”unique”:”0″,”pick_select_text”:””,”pick_table_id”:””,”pick_table_index”:””,”pick_display”:””,”pick_where”:””,”pick_orderby”:””,”pick_groupby”:””},”datum”:{“id”:69,”name”:”datum”,”label”:”Datum”,”description”:”De datum dat de route gereden wordt”,”help”:””,”class”:””,”type”:”date”,”weight”:1,”pick_object”:””,”pick_val”:””,”sister_id”:””,”required”:”0″,”date_type”:”wp”,”date_format”:”dmy_dash”,”date_allow_empty”:”1″,”date_html5″:”0″,”oembed_enabled_providers_facebookcom”:”0″,”oembed_enabled_providers_hulucom”:”0″,”oembed_enabled_providers_instagramcom”:”0″,”pick_post_status”:[“publish”],”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″,”unique”:”0″,”date_repeatable”:”0″,”date_format_custom”:””,”date_format_custom_js”:””,”date_year_range_custom”:””},”week”:{“id”:70,”name”:”week”,”label”:”Week”,”description”:”De week dat de route vereden wordt”,”help”:””,”class”:””,”type”:”number”,”weight”:2,”pick_object”:””,”pick_val”:””,”sister_id”:””,”required”:”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_facebookcom”:”0″,”oembed_enabled_providers_hulucom”:”0″,”oembed_enabled_providers_instagramcom”:”0″,”pick_post_status”:[“publish”],”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″,”unique”:”0″,”number_repeatable”:”0″,”number_placeholder”:””},”vertrektijd”:{“id”:71,”name”:”vertrektijd”,”label”:”Tijd vertrek”,”description”:”De tijd van vertrek”,”help”:””,”class”:””,”type”:”time”,”weight”:3,”pick_object”:””,”pick_val”:””,”sister_id”:””,”required”:”0″,”time_type”:”12″,”time_format”:”h_mma”,”time_format_24″:”hh_mm”,”time_allow_empty”:”1″,”time_html5″:”0″,”oembed_enabled_providers_facebookcom”:”0″,”oembed_enabled_providers_hulucom”:”0″,”oembed_enabled_providers_instagramcom”:”0″,”pick_post_status”:[“publish”],”default_value”:”9:00″,”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″,”unique”:”0″,”time_repeatable”:”0″,”time_format_custom”:””,”time_format_custom_js”:””},”vertrekplaats”:{“id”:72,”name”:”vertrekplaats”,”label”:”Plaats van vertrek”,”description”:”De plaats vanwaar we vertrekken”,”help”:””,”class”:””,”type”:”text”,”weight”:4,”pick_object”:””,”pick_val”:””,”sister_id”:””,”required”:”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_facebookcom”:”0″,”oembed_enabled_providers_hulucom”:”0″,”oembed_enabled_providers_instagramcom”:”0″,”pick_post_status”:[“publish”],”default_value”:”De Vos en de Craen”,”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″,”unique”:”0″,”text_repeatable”:”0″,”text_placeholder”:””}},”show_in_menu”:”1″,”label_singular”:”Agenda Fietsroutes”,”public”:”1″,”show_ui”:”1″,”supports_title”:”0″,”supports_editor”:”0″,”publicly_queryable”:”1″,”exclude_from_search”:”0″,”capability_type”:”post”,”capability_type_custom”:”agenda_fietsroutes”,”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″,”menu_position”:”0″,”menu_icon”:”dashicons-calendar”,”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”:”custom”,”rest_enable”:”0″,”read_all”:”0″,”write_all”:”0″,”pfat_filter_archive_custom”:”the_content”},”58″:{“id”:58,”name”:”fietsroute”,”label”:”Fietsroutes”,”description”:””,”type”:”post_type”,”storage”:”meta”,”object”:””,”alias”:””,”fields”:{“omschrijving”:{“id”:59,”name”:”omschrijving”,”label”:”Omschrijving”,”description”:”Geef een korte omschrijving van de route”,”help”:””,”class”:””,”type”:”paragraph”,”weight”:0,”pick_object”:””,”pick_val”:””,”sister_id”:””,”required”:”0″,”paragraph_allow_html”:”1″,”paragraph_oembed”:”0″,”paragraph_wptexturize”:”1″,”paragraph_convert_chars”:”1″,”paragraph_wpautop”:”1″,”paragraph_allow_shortcode”:”0″,”paragraph_allowed_html_tags”:”strong em a ul ol li b i”,”paragraph_max_length”:”0″,”oembed_enabled_providers_facebookcom”:”0″,”oembed_enabled_providers_hulucom”:”0″,”oembed_enabled_providers_instagramcom”:”0″,”pick_post_status”:[“publish”],”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″,”unique”:”0″,”paragraph_repeatable”:”0″,”paragraph_placeholder”:””},”routekaart”:{“id”:60,”name”:”routekaart”,”label”:”Kaart van de route”,”description”:”Upload een kaart van de route”,”help”:””,”class”:””,”type”:”file”,”weight”:1,”pick_object”:”custom-simple”,”pick_val”:””,”sister_id”:””,”required”:”0″,”file_format_type”:”single”,”file_uploader”:”attachment”,”file_attachment_tab”:”upload”,”file_edit_title”:”1″,”file_show_edit_link”:”0″,”file_linked”:”0″,”file_limit”:”0″,”file_restrict_filesize”:”10MB”,”file_type”:”images”,”file_field_template”:”rows”,”file_add_button”:”Bestand Toevoegen”,”file_modal_title”:”Voeg een bestand toe”,”file_modal_add_button”:”Bestand Toevoegen”,”file_wp_gallery_output”:”0″,”file_wp_gallery_link”:”post”,”file_wp_gallery_columns”:”1″,”file_wp_gallery_random_sort”:”0″,”file_wp_gallery_size”:”thumbnail”,”oembed_enabled_providers_facebookcom”:”0″,”oembed_enabled_providers_hulucom”:”0″,”oembed_enabled_providers_instagramcom”:”0″,”pick_post_status”:[“publish”],”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″,”unique”:”0″,”file_allowed_extensions”:””},”afstand”:{“id”:61,”name”:”afstand”,”label”:”Afstand”,”description”:”Geef hier de (globale) afstand van de route in”,”help”:””,”class”:””,”type”:”number”,”weight”:2,”pick_object”:””,”pick_val”:””,”sister_id”:””,”required”:”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_facebookcom”:”0″,”oembed_enabled_providers_hulucom”:”0″,”oembed_enabled_providers_instagramcom”:”0″,”pick_post_status”:[“publish”],”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″,”unique”:”0″,”number_repeatable”:”0″,”number_placeholder”:””},”fotos”:{“id”:62,”name”:”fotos”,”label”:”Foto’s”,”description”:”Upload foto’s van de route”,”help”:””,”class”:””,”type”:”file”,”weight”:3,”pick_object”:”custom-simple”,”pick_val”:””,”sister_id”:””,”required”:”0″,”file_format_type”:”multi”,”file_uploader”:”attachment”,”file_attachment_tab”:”upload”,”file_edit_title”:”1″,”file_show_edit_link”:”0″,”file_linked”:”0″,”file_limit”:”6″,”file_restrict_filesize”:”10MB”,”file_type”:”images”,”file_field_template”:”rows”,”file_add_button”:”Bestand Toevoegen”,”file_modal_title”:”Voeg een bestand toe”,”file_modal_add_button”:”Bestand Toevoegen”,”file_wp_gallery_output”:”0″,”file_wp_gallery_link”:”post”,”file_wp_gallery_columns”:”1″,”file_wp_gallery_random_sort”:”0″,”file_wp_gallery_size”:”thumbnail”,”oembed_enabled_providers_facebookcom”:”0″,”oembed_enabled_providers_hulucom”:”0″,”oembed_enabled_providers_instagramcom”:”0″,”pick_post_status”:[“publish”],”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″,”unique”:”0″,”file_allowed_extensions”:””},”gpx_bestand”:{“id”:63,”name”:”gpx_bestand”,”label”:”GPX
bestand”,”description”:”Upload GPX bestand van de route”,”help”:””,”class”:””,”type”:”file”,”weight”:4,”pick_object”:”custom-simple”,”pick_val”:””,”sister_id”:””,”required”:”0″,”file_format_type”:”single”,”file_uploader”:”attachment”,”file_attachment_tab”:”upload”,”file_edit_title”:”1″,”file_show_edit_link”:”0″,”file_linked”:”0″,”file_limit”:”0″,”file_restrict_filesize”:”10MB”,”file_type”:”images”,”file_field_template”:”rows”,”file_add_button”:”Bestand Toevoegen”,”file_modal_title”:”Voeg een bestand toe”,”file_modal_add_button”:”Bestand Toevoegen”,”file_wp_gallery_output”:”0″,”file_wp_gallery_link”:”post”,”file_wp_gallery_columns”:”1″,”file_wp_gallery_random_sort”:”0″,”file_wp_gallery_size”:”thumbnail”,”oembed_enabled_providers_facebookcom”:”0″,”oembed_enabled_providers_hulucom”:”0″,”oembed_enabled_providers_instagramcom”:”0″,”pick_post_status”:[“publish”],”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″,”unique”:”0″,”file_allowed_extensions”:””}},”show_in_menu”:”1″,”label_singular”:”Fietsroute”,”public”:”1″,”show_ui”:”1″,”supports_title”:”1″,”supports_editor”:”0″,”publicly_queryable”:”1″,”exclude_from_search”:”0″,”capability_type”:”post”,”capability_type_custom”:”fietsroute”,”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_event_cat”:”0″,”built_in_taxonomies_event_listing_category”:”0″,”built_in_taxonomies_link_category”:”0″,”built_in_taxonomies_post_tag”:”0″,”menu_position”:”0″,”menu_icon”:”dashicons-location-alt”,”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”:”0″,”read_all”:”0″,”write_all”:”0″}}}I’ve got 3 questions/remarks about the code in the template:
1) should get_the_id() return a number? When I echoed it, it show the post-type, not a number.
2) The variable $wdtv_related is empty, so the foreach part doesn’t get executed.
3) the last part of the template (the divs) isn’t correct at the moment, it needs to be altered, but that’s the result of many tries to get the php part working.Hope you have enough information to give any suggestions.
Thanks in advance,
Bert.Hello @berttervoert
1) should get_the_id() return a number? When I echoed it, it show the post-type, not a number.
It should indeed return the current post ID. Assuming you are on a post page or within the loop.
2) The variable $wdtv_related is empty, so the foreach part doesn’t get executed.
This is quite understandable.
What is your Pod called exactly?agenda_fietsroute
oragenda_fietsroutes
?
You’ve used both so that cannot be right.3) the last part of the template (the divs) isn’t correct at the moment, it needs to be altered, but that’s the result of many tries to get the php part working.
Okidoki!
Cheers, Jory
Hello @jory,
ad 2) that is a typo indeed. Changed it to agenda_fietsroutes, which is the correct name for the pod.
the part of the code that doesn’t seem to work is now:
// Get additional info from related pod $wdtv_pod = pods( 'agenda_fietsroutes', get_the_id() ); echo $wdtv_pod; $wdtv_releated = $wdtv_pod->field( 'relationship_field' ); if ( !empty ( $wdtv_related ) ) { foreach ( $wdtv_related as $wdtv_rel ) { $wdtv_id = $wdtv_rel[ 'ID' ]; } } else { echo " geen relaties gevonden"; } ?>
The line: echo $wdtv_pod; shows on the page: post_type: agenda_fietsroutes. And the line in the ‘else’ statement gets displayed.
Somewhere in the forumposts I came across the suggestion to add ?pods_debug_sql=1 to the page url. This throws out the following:Fatal error: Uncaught ArgumentCountError: Too few arguments to function PodsData::get_sql(), 0 passed in C:\xampp\htdocs\door(en)trappers\wp-content\plugins\pods\classes\PodsData.php on line 718 and exactly 1 expected in C:\xampp\htdocs\door(en)trappers\wp-content\plugins\pods\classes\PodsData.php:3528 Stack trace: #0 C:\xampp\htdocs\door(en)trappers\wp-content\plugins\pods\classes\PodsData.php(718): PodsData->get_sql() #1 C:\xampp\htdocs\door(en)trappers\wp-content\plugins\pods\classes\Pods.php(2715): PodsData->select(Object(stdClass)) #2 C:\xampp\htdocs\door(en)trappers\wp-content\plugins\pods\classes\Pods.php(389): Pods->find(Object(stdClass)) #3 C:\xampp\htdocs\door(en)trappers\wp-content\plugins\pods\includes\classes.php(22): Pods->__construct('agenda_fietsrou...', Array) #4 C:\xampp\htdocs\door(en)trappers\wp-content\themes\hestia-child\wdtv\templateparts\wdtv_upcoming_programm.php(22): pods('agenda_fietsrou...', Array) #5 C:\xampp\htdocs\door(en)trappers\wp-includes\template.php(732): require('C:\\xampp\\htdocs...' in C:\xampp\htdocs\door(en)trappers\wp-content\plugins\pods\classes\PodsData.php on line 3528
Hope this makes any sense to you. But I think it is a problem that the line
$wdtv_pod = pods( 'agenda_fietsroutes', get_the_id() );
doesn’t seem to return the id. And is this the cause for the fatal error?Hope to hear from you,
Bert.Hi @jory,
After some more trial and error, I managed to get the id of the post(s) using the following line of code after
if ( $wdtv_pods->total() > 0 ) { while ( $wdtv_pods->fetch() ) {
$wdtv_pod_id = $wdtv_pods->display( 'id');
I’m still in the loop that gets the info from the agenda_fietsroutes pod. Might this be a problem? Is it possisble to nest a pods-loop within a pods-loop (an nested loop)?
I hope to get a reaction from you. Meanwhile I’ll keep trying to get this to work.
Thank you so far,
Bert.- This reply was modified 4 years ago by berttervoert.
- This reply was modified 4 years ago by berttervoert.
The display method should never be used to get the ID.
Always make sure you use the correct function for the current purpose.
Since you don’t be using the ID on the actual page a method nameddisplay
already indicates it’s not meant for what you want to do.You can just use
$wdtv_pods->id()
.Is it possisble to nest a pods-loop within a pods-loop (an nested loop)?
Please look at the
field()
method in the code or documentation for fetching relationships (https://pods.io/docs/code/pods/field/).
This method will (by default) return an array of relationships.
You can then loop through this array.I would advice you to learn more about PHP and how functions, loops, objects etc. work.
Cheers, Jory
Hi @jory,
I changed that line of code. I’m trying to get things working using the pods tutorial “get values from a relationship field”, but when I use the line:
$wdtv_related = $wdtv_pod->field( 'title' );
I get aFatal error: Uncaught Error: Call to a member function field() on int in C:\xampp\htdocs\door(en)trappers\wp-content\themes\hestia-child\wdtv\templateparts\wdtv_upcoming_programm.php:38 Stack trace: #0 C:\xampp\htdocs\door(en)trappers\wp-includes\template.php(732): require() #1 C:\xampp\htdocs\door(en)trappers\wp-includes\template.php(676): load_template('C:\\xampp\\htdocs...', false, Array) #2 C:\xampp\htdocs\door(en)trappers\wp-includes\general-template.php(204): locate_template(Array, true, false, Array) #3 C:\xampp\htdocs\door(en)trappers\wp-content\themes\hestia-child\wdtv_shortcodes.php(15): get_template_part('/wdtv/templatep...') #4 C:\xampp\htdocs\door(en)trappers\wp-includes\shortcodes.php(343): wdtv_programm_upcoming('', '', 'wdtv_programm_u...') #5 [internal function]: do_shortcode_tag(Array) #6 C:\xampp\htdocs\door(en)trappers\wp-includes\shortcodes.php(218): preg_replace_callback('/\\[(\\[?)(wdtv_p...', 'do_shortcode_ta...', '\n<div class="wp...') #7 C:\xampp\htdocs\door(en)trappers\wp-includes\class-wp-hook. in C:\xampp\htdocs\door(en)trappers\wp-content\themes\hestia-child\wdtv\templateparts\wdtv_upcoming_programm.php on line 38
My code so far is:
<div class="wdtv_club_titel">Programma aankomende weken:</div> <?php // Get the weeknumber for the current week and the next week $cur_week_nr = date('W'); $nxt_week_nr = ($cur_week_nr + 1); // Set up the parameters for pods::find $params = array( 'where' => 'week.meta_value = "' . $cur_week_nr . '" OR week.meta_value = "' . $nxt_week_nr . '"', 'orderby' => 'datum.meta_value', 'limit' => -1 ); // Run the find $wdtv_pods = pods( 'agenda_fietsroutes', $params ); if ( $wdtv_pods->total() > 0 ) { while ( $wdtv_pods->fetch() ) { $wdtv_pod = $wdtv_pods->id(); $route = $wdtv_pods->display( 'route' ); $datum = $wdtv_pods->display( 'datum' ); $tijd_vertrek = $wdtv_pods->display( 'vertrektijd' ); $plaats_vertrek = $wdtv_pods->display( 'vertrekplaats' ); ?> <div id="wdtv_programma_container"> <?php // Get additional info from related pod //$wdtv_pod = pods( 'agenda_fietsroutes', get_the_id() ); echo $wdtv_pod; $wdtv_related = $wdtv_pod->field( 'fietsroute.title' ); if ( !empty ( $wdtv_related ) ) { // foreach ( $wdtv_related as $wdtv_rel ) { // $wdtv_id = $wdtv_rel[ 'ID' ]; // } } else { echo " geen relaties gevonden"; } ?> <div id="wdtv_programma_item"> Op <?php echo $datum; ?> rijden we de <?php echo '<a href="' . esc_url( get_permalink( $id ) ) . '">' . $route . '</a>'; ?> </div> </div><?php } } else { ?>er staan geen activiteiten gepland voor de komende weken.<?php } ?>
Line 38 is the line that starts with $wdtv_related =
I’ve tried some of the available options as mentioned on the field() documentation page, but it keeps throwing that error. I did a copy and paste of that line of code to be sure there wasn’t a typo in it, but no change of result.Bert.
That is only logical because of this line:
$wdtv_pod = $wdtv_pods->id();
You overwrite the Pods object with the ID of that object.
You can just remove that line.Hi @jory,
Thank you so much for your answers and patience! I finally got this working. My – working – template now looks like this:
<?php /* Template Name: wdtv upcoming programm Template Post Type: post, page, fietsroutes, agenda_fietsroutes Description: Template om de komende fietsroutes van het programma weer te geven op de homepages. */ ?> <div class="wdtv_club_titel">Programma aankomende weken:</div> <?php // Get the weeknumber for the current week and the next week $cur_week_nr = date('W'); $nxt_week_nr = ($cur_week_nr + 1); // Set up the parameters for pods::find $params = array( 'where' => 'week.meta_value = "' . $cur_week_nr . '" OR week.meta_value = "' . $nxt_week_nr . '"', 'orderby' => 'datum.meta_value', 'limit' => -1 ); // Run the find $wdtv_pods = pods( 'agenda_fietsroutes', $params ); if ( $wdtv_pods->total() > 0 ) { while ( $wdtv_pods->fetch() ) { $route = $wdtv_pods->display( 'route' ); $datum = $wdtv_pods->display( 'datum' ); $tijd_vertrek = $wdtv_pods->display( 'vertrektijd' ); $plaats_vertrek = $wdtv_pods->display( 'vertrekplaats' ); ?> <div id="wdtv_programma_container"> <?php // Get additional info from related pod $wdtv_related = $wdtv_pods->field( 'route' ); if ( !empty ( $wdtv_related ) ) { $wdtv_id = $wdtv_related[ 'ID' ]; $wdtv_distance = get_post_meta( $wdtv_id, 'afstand', true ); } else { echo " geen relaties gevonden"; } ?> <div id="wdtv_programma_item"> Op <?php echo $datum; ?> rijden we de <?php echo '<a href="' . esc_url( get_permalink( $wdtv_id ) ) . '">' . $route . '</a>'; ?><br> Lengte: <?php echo $wdtv_distance; ?> km. </div> </div><?php } } else { ?>er staan geen activiteiten gepland voor de komende weken.<?php } ?>
As you can see, I even got some extra info from the related pod (distance).
I learned a lot from this and there is still a lot to learn! I’m gonna give pods a 5 star rating on wordpress. Is there a place where you can share your code for others with similar problems?Thanks again,
Bert.- This reply was modified 4 years ago by berttervoert.
Good to hear you’ve solved it!
And indeed, I think you would greatly benefit from learning more about PHP and the WordPress codebase in general. There is a lot available online to learn from..
As for sharing the code. When we feel like a case should be mentioned in the documentation we will, though our documentation isn’t meant to cover general PHP knowledge.
Normally users look for similar issues in this forum first. That is why I keep replying in English ??
Other great resources are php.net, wordpress.stackexchange.com and GitHub.Vriendelijke groeten ??
Jory
- The topic ‘Can’t get values from related post’ is closed to new replies.