Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #740206

    I have a custom taxonomy archive and the posts are ordered by custom_value_num and it is working great. The problem is that it is only sorting the posts of the current page, so page number 2 has items with smaller custom field value than the first page.

    How would i get it to work like that it gets all the values and sorts all the posts and not just current page?

    Here is the taxonomy-kello.php loop and the value is “hinta”:

              <?php
                        $avia_config['blog_style'] = apply_filters('avf_blog_style', avia_get_option('blog_style','multi-big'), 'archive');
                        if($avia_config['blog_style'] == 'blog-grid')
                        {
                            global $posts;
                            $post_ids = array();
                            foreach($posts as $post) $post_ids[] = $post->ID;
    
                            if(!empty($post_ids))
                            {
                          
                                $atts   = array(
                                    'type' => 'grid',
                                    'items' => get_option('posts_per_page'),
                                    'columns' => 4,
                                    'class' => 'avia-builder-el-no-sibling',
                                    'paginate' => 'yes',
                                    'use_main_query_pagination' => 'yes',
                                    'custom_query' => array( 
                                    	'post__in'=>$post_ids, 
                                    	'post_type'=>get_post_types(), 
                                    	'meta_key' => 'hinta', 
                                    	'orderby' => 'meta_value_num', 
                                    	'order' => 'asc', 
                                    	),
                                );
     							 
    
                                $blog = new avia_post_slider($atts);
                                $blog->query_entries();
                                echo "<div class='entry-content-wrapper'>".$blog->html()."</div>";
                            }
                            else
                            {
                                get_template_part( 'includes/loop', 'index' );
                            }
                    }
                        else
                        {
                            /* Run the loop to output the posts.
                            * If you want to overload this in a child theme then include a file
                            * called loop-index.php and that will be used instead.
                            */
    
                            $more = 0;
                            get_template_part( 'includes/loop', 'index' );
                        }
                        ?>
    #742054

    Hey salesmusat,

    Can you give us temporary admin access? so we can check it further. Also ftp access? so we can try to tweak the code. Just place the details in the Private Content so only moderators can view it.

    Best regards,
    Nikko

    #743932

    Sure!

    #745899

    Hi,

    Thanks for giving us access and patience for a bit delayed reply (I haven’t fixed it after few tries), It should be fixed now. I have modified this part of the code:

    if(!empty($post_ids))
        {
    
            $atts   = array(
                'type' => 'grid',
                'items' => get_option('posts_per_page'),
                'columns' => 4,
                'class' => 'avia-builder-el-no-sibling',
                'paginate' => 'yes',
                'use_main_query_pagination' => 'yes',
              	'custom_query' => array( 
                	'meta_query' => array(
        			 	array(
                         'key' => 'valikoimassa',
                         'value' => 'ei',
                         'compare' => 'NOT EXISTS' 
                      	)
                    ) ,
                    'meta_key' => 'Hinta',
                	'orderby' => 'meta_value_num', 
                	'order' => 'asc',
                	/*'post__in'=>$post_ids, */
                	'post_type'=>get_post_types(),
        			'tax_query' => array(
        		    	array(
        		    		'taxonomy' => $tax_name,
        		    		'field' => 'term_id',
        		    		'terms' => $tax_id
        		    	)
        		  	),
                ),
    
            );

    to:

    if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); }
    elseif ( get_query_var( 'page' ) ) { $paged = get_query_var( 'page' ); }
    else { $paged = 1; }
    
    $tax_id = get_queried_object()->term_id;
    $tax_name = get_queried_object()->taxonomy;
    
    if(!empty($post_ids))
    {
    
        $atts   = array(
            'type' => 'grid',
            'items' => get_option('posts_per_page'),
            'columns' => 4,
            'class' => 'avia-builder-el-no-sibling',
            'paginate' => 'yes',
            'use_main_query_pagination' => 'yes',
            'custom_query' => array( 
                'meta_query' => array(
                    array(
                     'key' => 'valikoimassa',
                     'value' => 'ei',
                     'compare' => 'NOT EXISTS' 
                    )
                ) ,
                'meta_key' => 'Hinta',
                'orderby' => 'meta_value_num', 
                'order' => 'asc',
                /*'post__in'=>$post_ids, */
                'post_type'=>get_post_types(),
                'tax_query' => array(
                    array(
                        'taxonomy' => $tax_name,
                        'field' => 'term_id',
                        'terms' => $tax_id
                    )
                ),
                'paged' => $paged,
            ),
    
        );

    Let us know if it’s working fine :)

    Best regards,
    Nikko

    #746233

    Hi!

    Yeah that works like a charm!

    Thank you very much! :)

    #746241

    Hi!

    Happy we can help.
    Please feel free to let us know if we can do anything else for you.

    Thanks a lot

    Cheers!
    Basilis

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Sorting by custom_value_num is working only in current page.’ is closed to new replies.