Looping through WP_Post Object

Based on what you said about a post being completed, you can check if its status is completed and if it is, then point to the title: foreach ( $lessons as $lesson ){ if( $lesson[‘status’] == ‘completed’ ){ echo $lesson[‘post’]->post_title; } }

How to save WordPress Options as an array?

Have you tried… <input type=”text” name=”my_options[option1]” value=”<?php echo $options[‘option1’]; ?>” /> <input type=”text” name=”my_options[option2]” value=”<?php echo $options[‘option2’]; ?>” /> <input type=”text” name=”my_options[option3]” value=”<?php echo $options[‘option3′]; ?>” />? I should say though (and maybe you have), that you should register your settings and perform necessary validation checks on the input – or if you really don’t … Read more

Get Term names from WP Term Object

Here’s an alternative using the handy wp_list_pluck(): $terms = get_terms(array( ‘taxonomy’ => ‘category’, ‘hide_empty’ => false, )); $slugs = wp_list_pluck( $terms, ‘slug’ ); $names = wp_list_pluck( $terms, ‘name’ ); where we pluck out the wanted field into an array.

if is_singular array not working as expected

You are using an incorrect check here. is_singular() returns true when a post is from the specified post type or post types or the default post types when none is specified. You cannot target specific single posts with is_singular() You have to use is_single to target a specific post if ( is_single( ‘post-a’ ) { … Read more

Show one post per author and limit query to 8 posts

I believe that you can achieve this effect by grouping the query by author ID, which will require a filter(mostly cribbed from the Codex): function my_posts_groupby($groupby) { global $wpdb; $groupby = “{$wpdb->posts}.post_author”; return $groupby; } add_filter( ‘posts_groupby’, ‘my_posts_groupby’ ); If you have less than 8 authors, however, this won’t work. (You will get a number … Read more

settings api store multiple array

I put this in the form so it knows its editting: <form method=”post” action=”options.php”> <?php settings_fields(‘venues_section’); ?> <input type=”hidden” name=”editmode” value=”<?php echo $editmode; ?>” /> <input type=”hidden” name=”venue_id” value=”<?php echo $venue_id; ?>” /> <?php submit_button(); ?> </form> The receiving validation function can then handle that by doing something like this: function venues_validation_callback($input){ $venues = get_option(‘venues’); … Read more