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:
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
$arg_zeroth
. Or am I wrong about that?