Posted: January 23, 2018 at 6:54 am
Hi EE Team, I am trying to get, outside the loop, a venue meta value like this : where vnu_phone is the name of the meta field (grabbed in the chrome inspector) I am trying to get the value. Am I missing something ? Thanks in advance for your help. Patrick |
|
Hi Patrick, The venue phone field isn’t actually stored in post meta. You can use the If you check the source: |
|
Thank you Josh, But I have already tried this template tag function. Maybe it’s because I am trying to get an event field outside of my custom event template post ? The following query works well (which I also need) : I am customizing the content-espresso_events.php which I have copied in my child theme. I need to get an additional venue meta in this template. Should I call back the EEH_Event_View object using something similar to this : Sorry, not sure 100% what I am doing at this time. |
|
Correct, because the template tag I shared with you will only work within a venue custom post type.
May I ask what exactly are you trying to get? Is it really meta data or some other field that’s included in the Venue editor? |
|
I am trying to get the venue phone of a venue that is not related to the current event post (indeed in the Venue editor). Here is a portion of my code inside content-espresso_events.php :
<?php $lieu_id = espresso_venue_id( $post->ID ); $lieu_category = get_the_terms( $lieu_id, ‘espresso_venue_categories’ ); if ( $lieu_category[0]->slug == ‘organismes’ ) : ?> <span><strong>Pour information :</strong></span><br/> <span><?php the_field(‘nom_public_de_lorganisme’, $lieu_id);?></span><br/> <?php elseif ( $lieu_category[0]->slug == ’emplacements’ ) : ?> <?php $org_resp_id = absint ( get_field( ‘organisme_responsable’, $lieu_id ) ); ?> <span><strong>Pour information :</strong></span><br/> <span><?php the_field(‘nom_public_de_lorganisme’, $org_resp_id);?></span><br/> <?php endif; ?> </div> |
|
Sorry, for some reason, the triple backtick did’nt work in my previous reply… |
|
We ask that code not be posted here, can you use a gist or a pastebin? It’s not clear from your code, how are you getting the venue ID of the venue that is not related to the current event post? |
|
Sorry for the code. I am trying to get the venue phone of a venue that is not related to the current post (single event view).
Where $org_resp_id is the venue id of the unrelated event. |
|
If you already have the original venue ID you can use our models to pull an EE_Venue object:
As you then have the EE_Venue object you also have access to any other information for that venue if needed. |
|
How is it that you’re verifying the $org_resp_id is a valid venue ID? One thing that may be happening is the venue ID being passed into the espresso_venue_phone() tag might not be a valid venue ID, so it will help to at least add some validation e.g.:
|
|
Thanks Tony ! I knew intuitively I had to call the Venue model but did’nt dig enough ! Now working great ! I guest I can now get almost any EE fields I need to build all my templates. Regarding Josh comment on venue ID validation, I would like to say that I already made sure elsewhere that it is valid when trying to get the value. The problem is not with ID validation but with the fact that the template tag function espresso_venue_phone() does not work outside the event template, or should I say, outside the venue model. |
|
It does work outside of the event template and venue model. The problem is happening because the global post object is an EE event that has a venue assigned to it.
Because the post is an EE Event and has a venue assigned to it, that’s what you’re getting back on the second call to espresso_venue_phone(). I’ve created a ticket for our developers to investigate this but in the meantime, you can pull the EE venue object directly using the above 🙂 |
|
The support post ‘Venue meta values query outside the loop’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.