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 define category ID in an array?

As Geert pointed out, your current conditional will always be true. An if() construct needs to be fed an expression. You’re feeding it a valid array, so that’s true. Always. So far this is basic PHP, regardless of whether in a WP environment or not. As can be read in Chris_O’s comment if ( is_category(‘some-cat’) … 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

How do I find the first item in the post array?

You can get first item using this code <?php global $post; $the_post_ID = $post->ID; $n = get_posts(); $i=1; ?> <?php foreach ( $n as $post ) : ?> <nav id=”postNav”> <ul> <li<?php if ($i){ echo ‘ class=”current”‘; $i=0; }?>> <a href=”https://wordpress.stackexchange.com/questions/88596/<?php the_permalink(); ?>” title=”<?php printf( esc_attr__( ‘Permalink to %s’, ‘twentyten`enter code here`’ ), the_title_attribute( ‘echo=0’ … Read more

Explode Array from Repeatable Custom Field

This is more of a PHP question than a WordPress question. Try to replace $temp = explode( “|”, $am ); with $temp = explode( “|”, $am[0] ); since $am is an array. You should also consider using isset() to check if the array items exists. Here is one idea: <?php $affman = get_post_meta( $post->ID, ‘affiliatemanager’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)