0

We are trying to reorder one section of the home page.

our approach was with meta_keys and meta_values

WP_Query Sample:

    <ul id="featuredMain" class="feautrued-main">
      <!-- Main Featured -->
      <?php
      global $prefix;

   $args_main_feautred = array(
        'meta_key' => 'den_h_f_order',
        'meta_value' => '1',
        'posts_per_page' => 1,
        'post_type' => 'any',
        'post_status' => 'publish',
        'order' => 'ASC'
        );


      $args_2nd = array(
        'meta_key' => 'den_h_f_order',
        'meta_value' => '2',
        'posts_per_page' => 1,
        'post_type' => 'any',
        'post_status' => 'publish',
        'orderby' => 'date',
        'order' => 'ASC',
        );

      $args_3rd = array(
        'meta_key' => 'den_h_f_order',
        'meta_value' => '3',
        'posts_per_page' => 1,
        'post_type' => 'any',
        'post_status' => 'publish',
        'orderby' => 'date',
        'order' => 'ASC',
        );

      $args_4th = array(
        'meta_key' => 'den_h_f_order',
        'meta_value' => '4',
        'posts_per_page' => 1,
        'post_type' => 'any',
        'post_status' => 'publish',
        'orderby' => 'date',
        'order' => 'ASC',
        );


      $args_5th = array(
        'tag_slug__in' => array( 'destacado-video'),
        'posts_per_page' => 1,
        'post_status' => 'publish',
        'post_type' => 'media_videos'
        );

      $args_6th = array(
        'meta_key' => 'den_h_f_order',
        'meta_value' => '6',
        'posts_per_page' => 1,
        'post_type' => 'any',
        'post_status' => 'publish',
        'orderby' => 'date',
        'order' => 'ASC',
        );


      $args_7th = array(
        'meta_key' => 'den_h_f_order',
        'meta_value' => '7',
        'posts_per_page' => 1,
        'post_type' => 'any',
        'post_status' => 'publish',
        'orderby' => 'date',
        'order' => 'ASC',
        );


      $args_8th = array(
        'meta_key' => 'den_h_f_order',
        'meta_value' => '8',
        'posts_per_page' => 1,
        'post_type' => 'any',
        'post_status' => 'publish',
        'orderby' => 'date',
        'order' => 'ASC',
        );

      $first   = new WP_Query($args_main_feautred);
      $second  = new WP_Query($args_2nd);
      $third   = new WP_Query($args_3rd);
      $forth   = new WP_Query($args_4th);
      $fifth   = new WP_Query($args_5th);
      $sixth   = new WP_Query($args_6th);
      $seventh = new WP_Query($args_7th);
      $eight = new WP_Query($args_8th);
?>

Then I can select this order with:

Metaboxes

It is perhaps the must complicated way to reorder posts with out using a TAG or a Super Fancy Plugin.

My question now is about the logic of a conditional that if NONE is selected or nothing is selected at all, then a default fallback (orderby => data) take the place.

UPDATE

Conditional

If you notice I have a Checkbox in my Metaboxes called: "Activation home" .

So I tried:

    $homeorder_activation = get_post_meta( get_the_ID(), "{$prefix}h_d_order_activated", true );

if($homeorder_activation):

       $args_main_feautred = array(
            'meta_key' => 'den_h_f_order',
            'meta_value' => '1',
            'posts_per_page' => 1,
            'post_type' => 'any',
            'post_status' => 'publish',
            'order' => 'ASC'
            );
else :

       $args_main_feautred = array(
            'posts_per_page' => 1,
            'post_type' => 'any',
            'post_status' => 'publish',
            );
endif;

That won't work at all.

It will be amazing if you can point to another or better way to order posts.

thanks

4
  • I'm not sure if I understand your question. Supposing the selection is an option in the backoffice, you can detect whether it is empty and have a special set of arguments stored in $arg_zeroth. Or am I wrong about that?
    – cjbj
    Commented May 31, 2016 at 7:45
  • What about this kind of approach? I don't see 05 in your screenshot.
    – birgire
    Commented May 31, 2016 at 7:53
  • oh @cjbj I really tried to do: ` if($metabox_activated) do NEW WP QUERY endif;` but doesn't work well.
    – Locke
    Commented May 31, 2016 at 17:20
  • @birgire is because #5 is called by a TAG .
    – Locke
    Commented May 31, 2016 at 17:23

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.