As Tom has said in his comment, there is no option for WP_Query
for ordering posts by their word count/length.
If you wanted to do this then you would have to firstly store the word count or length of each post as post meta. Once this was stored, you could then use WP_Query
like so:
$args = array(
'posts_per_page' => 10,
'post_status' => 'publish',
'orderby' => 'meta_value_num',
'meta_key' => 'wordcount',
'order' => 'DESC',
);
$query = new WP_Query( $args );
You could store the word count of posts as post meta when updating posts or when new posts are created by using the following code:
/**
* Get post wordcount and save as post meta
*/
function add_post_wordcount( $post_id ) {
$content = get_post_field( 'post_content', $post_id ); // Get the content
$wordcount = str_word_count( strip_tags( $content ) ); // Count the words
if ( ! add_post_meta( $post_id, 'wordcount', $wordcount, true ) ) {
update_post_meta( $post_id, 'wordcount', $wordcount );
}
}
Then, run this function on the following WordPress actions:
On save new post
add_action( 'save_post', 'add_post_wordcount' );
On updating existing post
add_action( 'post_updated', 'add_post_wordcount' );