Hello!
Firstly, thanks for the awesome plugin!
I have two questions:
1) How can I get all values from my acf.
Now I using this
global $wpdb;
$years = $wpdb->get_results( 'SELECT DISTINCT meta_value FROM wp_postmeta WHERE meta_key LIKE "year"', OBJECT );
But I think it’s not a good tone.
2) How can I create the filter by ‘year’ acf?
I’m trying to follow this guide but without any luck.
I’m getting 404 error when I’m going to /year?=2017.
Thanks!
The problem is that your url with ?year=2017 is conflicting with a build in rewrite rule for year posts in the blog.
What you need to do is change the variable from year
to something that does not conflict with a built in WP parameter.
@hube2 Thank you!
It’s done.
I used this ‘pre_get_posts’ function –
add_action( 'pre_get_posts', 'my_pre_get_posts' );
function my_pre_get_posts( $query ) {
if ( is_admin() ) {
return $query;
}
if ( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'post' ) {
if( isset($_GET['press']) ) {
$query->set('meta_key', 'press');
$query->set('meta_value', $_GET['press']);
}
}
return $query;
}