Support

Account

Home Forums Backend Issues (wp-admin) Exclude posts from loop based on custom field

Unread

Exclude posts from loop based on custom field

  • I’m getting myself tied up in knots here! I’m using a loop to list company staff members. The loop is filtering by a particular sub-field value ‘exec’ and then ordering by another custom field ‘staff_order_name’. It’s all working perfectly – this is what I have so far:

    $posts = get_posts(array(
    	'post_type' => 'staff',
    	'posts_per_page' => -1,
    	'meta_query' => [
    		[
    			'key' => 'staff_role_info_staff_type',
    			'compare' => 'LIKE',
    			'value' => 'exec'
    		],
    	],
    	'meta_key' => 'staff_order_name',
    	'orderby' => 'meta_value',
    	'order' => 'ASC'
    ));

    What I need to do now is to simply exclude posts from the loop that have another custom field ‘staff_priority’ filled in. Thanks in advance.

Viewing 1 post (of 1 total)

The topic ‘Exclude posts from loop based on custom field’ is closed to new replies.