Add a new "order by" filter with custom field values

Posted in: Newspaper
Post count: 23

HI,

I would like to add a new filter for the display of post on a page/page category/tag page/other page… with a custom fields like digit number or personnal alphabet.
This is a model of code i have:
$posts = get_posts(array(
‘post_type’ => ‘post’,
‘posts_per_page’ => -1,
‘meta_key’ => ‘rank’,
‘orderby’ => ‘meta_value_num’,
‘order’ => ‘ASC’
));

if( $posts ): ?>

<?php wp_reset_postdata(); ?>

<?php endif; ?>

This is the code i have to display custom field : <h1 class=”rang”><?php the_field(‘rank’); ?></h1>

This code filter display post with order by “Rank” which have digit value (or an other value type).
However, this code cannot be integrated with the filter options for the theme.
How can we ordered the display of post with a custom field descending or ascending way and how to display this custom field on each article?
What are the files to edit and how to do this?
Thanks

Post count: 6600

Hi,

Theme’s filters are built in the data source file, you can add your own custom sorting there: http://screencast.com/t/KIcNzrBi9yebhttps://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters and use the orderby meta value.

To display the filed in each articles you need to edit post’s template files and place the custom field where you would want it: http://screencast.com/t/lgIy395w

This job requires custom work so if you don’t have coding knowledge to make this implementations we advise you to turn to a freelancer as we’re not available for any customization services at the moment. You can find one site’s like: http://studio.envato.com/

Thanks for the message!

Viewing 2 posts - 1 through 2 (of 2 total)
The forum ‘Newspaper’ is closed to new topics and replies.