Wordpress: Archive page with Filter doesn't work (ACF)

回眸只為那壹抹淺笑 提交于 2019-12-04 06:32:43

I used your code to try and recreate your issue and ran into a number of issues but got it working. On the link you supplied the video tutorial does things differently to the sample code.

The first thing I noticed is that you are changing the $query in the functions then redefining it in archive-projekte.php

$args = array(
      'post_type' => 'projekte',
      'post_status' => 'publish',
      'posts_per_page' => '-1'
);
$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) : 
   while ( $the_query->have_posts() ) : 
      //......
   endwhile; 
endif;

wp_reset_query();

you can just use a version of the standard loop instead

if ( have_posts() ) {  
   while ( have_posts() ) {
      the_post();         
      //.......
   }
}

Secondly when I set the advanced custom field(mitglieder) in Wordpress admin to be a checkbox it is then rendered as a checkbox on the front end by create_field() in the filter div but the problem is that checkboxes are saved in the meta data as serialized data so it didn't work so I changed the advanced custom field to a radio button it all works fine.

The new issue created by this is that the filter div now has radio buttons. So I watched the video tutorial and output checkboxes using a foreach loop on $field instead of using create_field, this means that the javascript needs to be changed also.

Now the only issue remains is if you need you advanced custom field to be checkbox sothat one of your projekte posts to have more than one mitglieder value then you would need to work with the serialized meta data in order to make the filter work correctly.

This works like ACF example video which uses houses and bedrooms and in that case a house cannot be a 2 bedroom house and a 3 bedroom house at the same time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!