Skip to main content
  Thursday, September 06 2018
  7 Replies
  1K Visits
  Subscribe
It is possible to order by specific order in wp media folder in loop?

example with my code


$query = get_posts(array(
'post_type' => 'attachment',
'posts_per_page' => "1",
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'wpmf-category',
'field' => 'term_id',
'include_children' => false,
'operator' => 'IN',
'terms' => $term->term_id)
))
);
A
5 years ago
Hi,

Thanks for contacting us here about this extension.
It is possible to order by specific order in wp media folder in loop?

Do you mean custom order in a folder of WP Media Folder?

Best,
S
5 years ago
Hi,

Actually when i use a loop query it is filter by recently added i would like to use the custom order in wp media folder to display this order in front of my website.

Thank you in advance.
A
5 years ago
Hi,
Thanks for getting back to me with more information.
Please try to use the code below:


$query = get_posts(array(
'post_type' => 'attachment',
'posts_per_page' => "1",
'meta_key' => 'wpmf_order',
'orderby' => 'meta_value_num',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'wpmf-category',
'field' => 'term_id',
'include_children' => false,
'operator' => 'IN',
'terms' => $term->term_id)
))
);


Hope it helps!
Best,
S
5 years ago
Thank you,

Really awesome it's work like a charm.


:)
S
5 years ago
Another question about the order for custom folders

I have this code



$terms_folder = get_terms( 'wpmf-category', array(
// 'orderby' => 'count',
'orderby' => 'term_order',
'hide_empty' => 0,
'exclude' => array($private, 35),
'parent' => $_GET['fo'],
) );



This code retrieve the parent folder to display subfolders

What can i change to use custom order fodlers of wp-media-folder ??

Thank you in advance.
A
5 years ago
Hi,

Thanks for your response.
What can i change to use custom order fodlers of wp-media-folder ??

You can use this code:


$terms_folder = get_terms( 'wpmf-category', array(
// 'orderby' => 'count',
'orderby' => 'term_order',
'hide_empty' => 0,
'exclude' => array($private, 35),
'parent' => $_GET['fo'],
) );

$sorted_cats = array();
foreach($terms_folder as $cat){
$ordr = get_term_meta($cat>term_id, 'wpmf_order');
$sorted_cats[$ordr] = $cat;
}
ksort($sorted_cats);


Hope it helps!
Cheers,
S
5 years ago
Hi very code,

I just adapt this code a little.



$terms_folder = get_terms( 'wpmf-category', array(
'hide_empty' => 0,
'exclude' => array($private, 35),
'parent' => $_GET['fo'],
) );

$sorted_cats = array();
foreach($terms_folder as $cat){
$ordr = get_term_meta($cat->term_id, 'wpmf_order');
$sorted_cats[$ordr[0]] = $cat;
}
ksort($sorted_cats);



Thank you :D
  • Page :
  • 1
There are no replies made for this post yet.