• Resolved kbratkauskas

    (@kbratkauskas)


    Hi Team

    I am very happy to find this plugin and already went quite far, but need some help to move on.

    I am editing archive-{$post-type}.php template to achieve custom look of archive page. It contains two blocks of “Pods Item List”. First block shows a list of custom category and the second shows a list of custom post types. I would like to filter the block containing custom post type based on selected category. I guess I should enter some function in field “WHERE” and that function somehow should be dynamic. I already read about find() function definition, but I didn’t manage to find the solution.

    Could you please tell me what that function should look like?

    Thank you in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • It’s more of a wordpress question

    I usually simply use WP_Query on post meta and stay in the wordpress logics.

    Here an example of what can be placed on your archive.php template
    /my-custom-type/?archive=archive will reverse order based on a date in a pods field datetime_utc

    <?php
    
    add_action('pre_get_posts', 'custom_archive_filter');
    function custom_archive_filter($query) {
      if (
        !is_admin() &&
        $query->is_main_query() &&
        $query->is_post_type_archive('my-custom-type')
      ) {
        $is_archive = ($_GET['archive'] ?? '') === 'archive';
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    
        $metaQuery = ['relation' => 'AND'];
        $metaQuery[] = [
          'key'     => 'datetime_utc',
          'type'    => 'CHAR',
          'compare' => $is_archive ? '<' : '>=',
          'value'   => gmdate('Y-m-d H:i', time()),
        ];
        $query->set('meta_query', $metaQuery);
    
        $query->set('orderby', 'meta_value');
        $query->set('meta_key', 'datetime_utc');
    
        $query->set('order', $is_archive ? 'DESC' : 'ASC');
      }
    
      return $query;
    }
    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @kbratkauskas

    The suggestion of @cantoute is correct. WordPress archive pages use the loop from core, not Pods.

    Cheers, Jory

    Thread Starter kbratkauskas

    (@kbratkauskas)

    Thank you for your reply, Cantoute and Jory.

    I found that it’s possible to use worpress Query loop to display a list of category items. It’s simple. Also I feel that using Pods list item with the power of pods templates, could be more flexible solution. Maybe in the future ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to display pods in specific archive page’ is closed to new replies.