3200creative
9/10/2017 - 1:41 PM

acf example

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(). ?>