Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A few thoughts...</p> <p>It's not clear based on your examples whether or not you're using the WP_Query class to retrieve your event posts. The arguments passed to <code>tribe_get_events()</code> function suggest that you're just using <code>get_posts()</code> to retrieve event posts.</p> <p>I would recommend a secondary loop using <code>WP_Query</code>. This allows you to easily query for posts by meta_key/value:</p> <pre><code>$query_args = array( 'post_type' =&gt; 'event', 'meta_key' =&gt; '_artist_id', 'meta_value' =&gt; '5' ); $event_query = new WP_Query( $query_args ); if( $event_query-&gt;have_posts() ) { while( $event_query-&gt;have_posts() ) { $event_query-&gt;the_post(); ... // standard loop stuff goes here </code></pre> <p>This would return only event posts that had an <code>_artist_id</code> value of 5.</p> <p>See this page for details: <a href="http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters" rel="nofollow">http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters</a></p> <p>The caveat is that you can't use that with post meta values that are serialized. If you wanted to query by meta value, you would need to modify how you're storing event/artist data to break out fields you want to query by in to their own single post meta fields.</p> <p>However, a nice bonus for using <code>WP_Query</code> is that when posts are retrieved from the database all of their associated post meta is fetched as well and cached in memory. This means that calling <code>get_post_meta()</code> from inside a <code>WP_Query</code> loop will not generate additional database queries, as those values are stored in memory and <code>get_post_meta()</code> is wise enough to always check there first.</p> <p>A bigger issue your question hints at is one that many consider to be a shortcoming with WordPress -- it doesn't provide a bulletproof built-in standardized mechanism for relating posts to posts.</p> <p>For the gory details, check out the comment thread on this trac ticket: <a href="http://core.trac.wordpress.org/ticket/14513" rel="nofollow">http://core.trac.wordpress.org/ticket/14513</a></p> <p>A popular plugin that gets around the issue by creating a new database table to hold many-to-many relationships: <a href="http://wordpress.org/extend/plugins/posts-to-posts/" rel="nofollow">http://wordpress.org/extend/plugins/posts-to-posts/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload