Skip to content

Instantly share code, notes, and snippets.

@3200creative
Created September 10, 2017 13:41
Show Gist options
  • Save 3200creative/1003e3417c78554ce51da895c76b363e to your computer and use it in GitHub Desktop.
Save 3200creative/1003e3417c78554ce51da895c76b363e to your computer and use it in GitHub Desktop.
acf example
<?php
// filter
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'event_%", "meta_key LIKE 'event_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
// get the ID of the current page
$currentposttitle = get_the_title();
// args
$args = array(
'numberposts' => -1,
'post_type' => 'Events',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'event_%_location',
'value' => '"' . get_the_title() . '"',//I'm sure this is wrong but I'm assuming the key value isn't correct as a post object and the title has to be defined.
'compare' => '=',
'value' => $currentposttitle,
)
)
);
// query
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment