Skip to main content
deleted 33 characters in body
Source Link

I need to accomplish the following:

  • pull CPT tribe_events
  • sort by custom field "pin_to_top" in DESC order
  • get posts from today's date & any in the future
  • sort remaining posts in ASC order

My goal is to keep any posts with 'pin_to_top' = 1 at the top of the results, then display the remaining results in ASC order by event date.

Here's my query:

$data7 = array (
'post_status' => 'publish',
'ignore_sticky_posts' => 0,
// create array of arrays
'meta_query' => array(
    // pin to top array
    array(
        'meta_key' => 'pin_to_top',
        'meta_type' => 'NUMERIC',
        'meta_value_num' => '1',
        'compare' => '='
        ),
    // event start date array
    array(
        'meta_key' => '_EventStartDate',
        'meta_type' => 'DATETIME',
        'meta_value' => '$today',
        'compare' => '>='
        ),
    ),
// custom post type
'post_type' =>
  array (
    'tribe_events' => 'tribe_events'
),
// categories of custom post type
'tribe_events_cat' => 'events',
// sorting
'orderby' => array(
    'pin_to_top' => 'DESC',
    '_EventStartDate' => 'ASC'
  ),
);

I am open to suggestions and please keep in mind that I'm just getting started with WP Dev. TIA

I need to accomplish the following:

  • pull CPT tribe_events
  • sort by custom field "pin_to_top" in DESC order
  • get posts from today's date & any in the future
  • sort remaining posts in ASC order

My goal is to keep any posts with 'pin_to_top' = 1 at the top of the results, then display the remaining results in ASC order by event date.

Here's my query:

$data7 = array (
'post_status' => 'publish',
'ignore_sticky_posts' => 0,
// create array of arrays
'meta_query' => array(
    // pin to top array
    array(
        'meta_key' => 'pin_to_top',
        'meta_type' => 'NUMERIC',
        'meta_value_num' => '1',
        'compare' => '='
        ),
    // event start date array
    array(
        'meta_key' => '_EventStartDate',
        'meta_type' => 'DATETIME',
        'meta_value' => '$today',
        'compare' => '>='
        ),
    ),
// custom post type
'post_type' =>
  array (
    'tribe_events' => 'tribe_events'
),
// categories of custom post type
'tribe_events_cat' => 'events',
// sorting
'orderby' => array(
    'pin_to_top' => 'DESC',
    '_EventStartDate' => 'ASC'
  ),
);

I am open to suggestions and please keep in mind that I'm just getting started with WP Dev. TIA

I need to accomplish the following:

  • pull CPT tribe_events
  • sort by custom field "pin_to_top" in DESC order
  • get posts from today's date & any in the future
  • sort remaining posts in ASC order

My goal is to keep any posts with 'pin_to_top' = 1 at the top of the results, then display the remaining results in ASC order by event date.

Here's my query:

$data7 = array (
'post_status' => 'publish',
// create array of arrays
'meta_query' => array(
    // pin to top array
    array(
        'meta_key' => 'pin_to_top',
        'meta_type' => 'NUMERIC',
        'meta_value_num' => '1',
        'compare' => '='
        ),
    // event start date array
    array(
        'meta_key' => '_EventStartDate',
        'meta_type' => 'DATETIME',
        'meta_value' => '$today',
        'compare' => '>='
        ),
    ),
// custom post type
'post_type' =>
  array (
    'tribe_events' => 'tribe_events'
),
// categories of custom post type
'tribe_events_cat' => 'events',
// sorting
'orderby' => array(
    'pin_to_top' => 'DESC',
    '_EventStartDate' => 'ASC'
  ),
);

I am open to suggestions and please keep in mind that I'm just getting started with WP Dev. TIA

Source Link

Pin to Top Functionality using orderby custom field then event date

I need to accomplish the following:

  • pull CPT tribe_events
  • sort by custom field "pin_to_top" in DESC order
  • get posts from today's date & any in the future
  • sort remaining posts in ASC order

My goal is to keep any posts with 'pin_to_top' = 1 at the top of the results, then display the remaining results in ASC order by event date.

Here's my query:

$data7 = array (
'post_status' => 'publish',
'ignore_sticky_posts' => 0,
// create array of arrays
'meta_query' => array(
    // pin to top array
    array(
        'meta_key' => 'pin_to_top',
        'meta_type' => 'NUMERIC',
        'meta_value_num' => '1',
        'compare' => '='
        ),
    // event start date array
    array(
        'meta_key' => '_EventStartDate',
        'meta_type' => 'DATETIME',
        'meta_value' => '$today',
        'compare' => '>='
        ),
    ),
// custom post type
'post_type' =>
  array (
    'tribe_events' => 'tribe_events'
),
// categories of custom post type
'tribe_events_cat' => 'events',
// sorting
'orderby' => array(
    'pin_to_top' => 'DESC',
    '_EventStartDate' => 'ASC'
  ),
);

I am open to suggestions and please keep in mind that I'm just getting started with WP Dev. TIA