• Resolved AToyansk

    (@atoyansk)


    Hi there,
    Is it possible to group the posts displayed using Custom Layouts by a custom field?
    I need to display something like this:

    ::Country 1::
    post 1
    post 4

    ::Country 2::
    post 3

    ::Country 3::
    post 2
    post 5

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter AToyansk

    (@atoyansk)

    I tried using the query_args filter, but nothing was displayed at all:

    
    function layout_query_args( $args ) {
    	$args = array(
    		'post_type' => 'Institutions',
    		'post_status' => 'publish',
    		'posts_per_page' => -1,
    		'meta_query' => array(
    			'relation' => 'AND',
    			array(
    				'key' => 'country_bd',
    				'value' => 'my-val',
    				'compare' => '='
    			),
    			array(
    				'key' => 'country_bd',
    				'value' => '',
    				'compare' => '!='
    			)
    		)
    	);
    
    	$the_query = new WP_Query( $args );
    	if ( $the_query->have_posts() ) : ?>
    	<ul>
    		<h2>
    			<?php $key; ?>
    		</h2>
    		<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    			<li id="post-<?php the_ID(); ?>">
    			</li>
    		<?php
    		endwhile;
    		wp_reset_postdata(); ?>
    	</ul>
    	<?php endif;
    }
    add_filter( 'custom-layouts/layout/query_args', 'layout_query_args', 10 );
    
    Plugin Author Code Amp

    (@codeamp)

    Hey @atoyansk

    That code looks a little off.

    Lets try to look at the issue another way (I hope I understood it correctly).

    Why don’t we create 3 seperate layouts, and for each one, restrict them to a specific country?

    If that sounds like what you are trying to do, or would work, then I can help with the logic to set that up.

    The other question would be, how are you creating layouts, via the block editor, or via our admin pages?

    Thanks

    • This reply was modified 2 years, 9 months ago by Code Amp.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Group posts by Custom field’ is closed to new replies.