Order Categories by Character Count

This is probably more a question about PHP rather than WordPress, and as such may be closed as off-topic for this site. That said, you can usort() to sort an array using a custom comparison function: usort( $listings->loop[‘cats’], function( $a, $b ){ return strlen( $a->name ) – strlen( $b->name ); } ); After the call … Read more

Why is my array_diff usage breaking things?

You’re getting the Fatal Error because array_diff() is comparing the WP_Term objects in your array to a string, and it can’t do that. Here’s one way to fix that: Replace $topic = array_diff($topic, [“expired”]); with: $my_topic = array(); foreach ( $topic as $term ) { if ( ‘expired’ !== $term->slug ) { // Adds $term … Read more

Force array to be a string [closed]

There are a few ways you can make an integer a string. Here are 2 main ways to make that happen Type Cast – $values_x[] = (string) $series[0][‘data’][$i][0] Double Quote – $values_x[] “{$series[0][‘data’][$i][0]}” Also, you might want to check for null first and assign a default $values_x = !empty($values_x) ? $values_x : array(‘2010’); If you … Read more

Retrieve Array from within Array [closed]

It looks like you are using Advanced Custom Fields. Your “Product ID” is storing the object, instead of just the ID. Below shows you how you can access the post ID, otherwise just change your field saving option for Product ID. It’s a simple foreach statement. foreach( $pages as $page ) { echo $page[‘product_id’]->ID; }

Query parsing only author ids

Assuming that you have an array of post objects in $my_posts… $authids = array_unique(wp_list_pluck($my_posts,’post_author’)); What you will get are the post authors for the current page of posts, not the post authors for all of the posts. If you want the authors for all of the posts you will have run another query. To run … Read more

How to create a cumulative posts and members count

Here is a very crude script I’ve knocked up to get what you are after: <?php require(‘wp-blog-header.php’); $posts = get_posts(‘numberposts=-1&order=ASC’); $posts_times = array(); foreach ($posts as $post) { $post_time = strtotime($post->post_date); $offset = $post_time % (60*60*24); $post_time -= $offset; $posts_times[$post_time]++; } $keys = array_keys($posts_times); $running_count = 0; $end_data = array(); for($i = $keys[0]; $i <= … Read more