0

I have a problem. I am using Hello Elementor child theme where I made new archive template. Now I added a category to the menu through categories menu item. The problem is that posts are not filtering correctly according to the categories. The code is following:

<?php
/**
 * The template for displaying archive pages.
 *
 * @package HelloElementor
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}
?>

<?php
$custom_query_args = (array(
   'post_type' => 'kampaania'
));

$custom_query_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$custom_query = new WP_Query( $custom_query_args );

$temp_query = $wp_query;
$wp_query   = NULL;
$wp_query   = $custom_query;

?>
<main id="content" class="site-main">

    <?php if ( apply_filters( 'hello_elementor_page_title', true ) ) : ?>
        <header class="page-header">
            <?php
         
            the_archive_title( '<h1 class="entry-title">', '</h1>' );
            the_archive_description( '<p class="archive-description">', '</p>' );
            ?>
        </header>
    <?php endif; ?>

    <div class="page-content">
        <?php
        while ($custom_query->have_posts() ) {
            $custom_query->the_post();

            $post_link = get_permalink();
            ?>
            <article class="post">
                <div class="post-thumbnail">
            <?php
                if ( has_post_thumbnail() ) {
                    printf( '<a href="%s">%s</a>', esc_url( $post_link ), get_the_post_thumbnail( $post, 'large' ) );
                } ?>
            
            </div>
            <div class="card-body">
               <?php 
                $field = get_field_object('kampaania_periood'); 
                $field2 = get_field_object('kampaania_kauplused');
                ?>
                <div class="bpost-title">
                    <?php
                    printf( '<h2 class="%s"><a href="%s">%s</a></h2>', 'entry-title', esc_url( $post_link ), wp_kses_post( get_the_title() ) );
                    ?>
                </div>
         
               <p class="kamp-period">
                    <span class="kamp-period-head"><?php echo $field['label']; ?></span> <?php echo $field['value']; ?>
               </p>

               <p class="post-excerpt">
                  <?php the_excerpt(); ?>
               </p>
         
               <p class="kamp-kaup"> 
                    <span class="kamp-period-head"><?php echo $field2['label']; ?></span> <?php echo $field2['value']; ?>
               </p>

               <a href="<?php the_permalink(); ?>" class="btn-closer">Osale kampaanias</a>
            </div>
                
            </article>
        <?php } ?>
    </div>

    <?php wp_link_pages(); ?>

    <?php
    global $wp_query;
    if ( $wp_query->max_num_pages > 1 ) :
        ?>
        <nav class="pagination">
            <?php /* Translators: HTML arrow */ ?>
            <div class="nav-previous"><?php next_posts_link( sprintf( __( '%s Vanemad kampaaniad', 'hello-elementor-child' ), '<span class="meta-nav">&larr;</span>' ) ); ?></div>
            <?php /* Translators: HTML arrow */ ?>
            <div class="nav-next"><?php previous_posts_link( sprintf( __( 'Uuemad kampaaniad %s', 'hello-elementor-child' ), '<span class="meta-nav">&rarr;</span>' ) ); ?></div>
        </nav>
    <?php endif; ?>


</main>

Have I missed anything?

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.