Show first posts with custom field not empty and order all by title
You can order posts by meta value check out the codex https://codex.wordpress.org/Class_Reference/WP_Query
You can order posts by meta value check out the codex https://codex.wordpress.org/Class_Reference/WP_Query
As suggested by @Sumit, the problem was in the template: there was a test that prevented the_content() to execute when the content was empty. <?php if ( $page->post_content && have_posts() ) while ( have_posts() ) : the_post(); ?> <?php the_content(); ?> <?php endwhile ?>
In the end it was a plugin and my code conflicting with each other. Both were saving my post_meta. Resulting in odd behavior of my code and functionality of retrieving the data.
I assume you’re already properly using the WP Metadata API https://codex.wordpress.org/Metadata_API to attach the field to new comments and you just want to backfill for existing comments by stuffing the database? If it was my problem, I wouldn’t bother and would assume in my code that absence of meta implied no likes. If you use … Read more
I think the sort is either alphabetical or numerical. There is no API way to provide more elaborate sorting rules to the query and messing with SQL for it would be likely impractical. Since you are retrieving complete set of posts (don’t have to worry about pagination) the easiest way would be: Request no sort … Read more
WordPress has remove_meta_box() function. You can use it to remove meta box like function remove_post_meta_box() { remove_meta_box( ‘meta_box_id’ , ‘post’ , ‘normal’ ); } add_action( ‘admin_menu’ , ‘remove_post_meta_box’ );
Textareas behave quite different to text inputs in the browser rendering engine. I cannot figure out the use case of a single line textarea without scroll bars. If you want to copy the default text input behaviour to all effects, what is wrong with using a simple input type=”text” instead for your custom field? If … Read more
You need an action called manage_$post_type_posts_custom_column. This will allow you to add columns to your custom posts page. To be more precise, you need a filter to generate the column and an action to fill it with content. In your case something like this (untested): add_filter( ‘manage_chimpmunks_posts_columns’, ‘set_custom_size_column’ ); add_action( ‘manage_chimpmunks_posts_custom_column’ , ‘fill_custom_size_column’, 10, 2 … Read more
$terms = get_terms( array( ‘taxonomy’ => ‘category’, ‘hide_empty’ => false, ) ); $sort = array(); //loop to list through all category foreach ( $terms as $term ) { $id = $term->ID; $name = $term->name; $args = array( ‘post_type’ => ‘post’, ‘category’ => $name, ); $query = new WP_Query( $args ); $sum = 0; if ($query->have_posts() … Read more
I’d set up… Teams and Tournaments as taxonomies Players and Managers as post types. If you link the taxonomies to both post types you will be able to link both Players and Managers to the same Team or Tournament. CPT UI is a pretty good plugin to help create and manage custom post types.