AnswerBun.com

Add custom field to Posts and sort by it

WordPress Development Asked by nikname on October 27, 2020

I want to add custom field, named score, for each post individually and store it in database so I can later order posts by that field. I need to make it available on post edit to change this value, so it would basically be an input text field which accept numbers 0 to 5. To do this, do I have to create custom post type, or is there a way to achieve it with ordinary posts section?

One Answer

The easiest approach would be to use the Advanced Custom Fields plugin.

A quick example for your situation (this example assumes you have access to your theme files, and can update the PHP for output of the 'Scores' field):

  1. Install and activate the plugin
  2. Navigate to Custom Fields in the left-hand nav
  3. Create a new Field Group
  4. Create a 'Scores' text field
  5. Output the 'Scores' field in your page/post
  6. Use WP_Query to load and sort the posts by your new 'Score' field

Good luck!

Answered by Pixelsmith on October 27, 2020

Add your own answers!

Related Questions

CREATE TABLE with dbDelta does not create table

1  Asked on October 30, 2021 by fcd

     

how to add shortcode widget at end of main blog page

1  Asked on October 30, 2021 by shubhamk

 

Placing background image over section divider

1  Asked on October 30, 2021 by user191925

   

jQuery Click event is not fired at all

1  Asked on October 30, 2021 by islam-hanafi

   

Make the product page as homepage WooCommerce

0  Asked on October 30, 2021 by gabriel-borges

     

How to be sure to get last page version without ANY cache?

2  Asked on October 30, 2021 by j-bizmai

   

How to grab posts in Gutenberg Block?

1  Asked on October 30, 2021 by stephen-sabatini

 

Custom post type permalink returns bad url

1  Asked on October 30, 2021 by ncti

     

Menus don’t appear in admin area / WordPress Multisite

0  Asked on October 30, 2021 by user191642

   

Client side HTTP parameter pollution (reflected)

0  Asked on October 30, 2021 by divided

 

WP Ajax Function Always Returning undefined

1  Asked on October 30, 2021 by brian-bruman

     

Group Posts by Category in Monthly Archive

2  Asked on October 30, 2021 by zero-goki

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP