Site logo

Archived topic

Create Archive based on custom field / meta_query

3 replies · Started by Samuel on February 20, 2021

Viewing posts 1–4 of 4

Hi,

I've created a custom field (using CMB2), it's just a checkbox. And now I want to create an archive that show only the posts with the checkbox turned to true.

I was able to create a query that returned only the posts that I want using:

$postsPT = new WP_Query( array(
    'post_status' => 'publish',
    'post_type' => 'any',
    'meta_query' => array(
         array(
            'key' => 'idioma_checkbox',
            'value' => "on",
            // 'compare' => 'IN'
        ) 
    )
   
  ) );

But I can't seem to figure out how the archives work. I'm able to create archives for custom post types, but not based on a custom field.
I duplicated the archive.php template because I want to keep the same design as the posts archive. But can't figure out the best approach.

What template does generate_do_template_part( 'archive' ); uses?

Thanks

Hi Tom,

Thanks for the clarification.
I wasn't understanding that it used that template.

I ended up ditching the custom field and was able to achieve what I wanted using a custom taxonomy, which has an archive by default.

Thanks!

Glad you got it sorted! :)

This archived topic is closed to new replies.