Store metakey value as an array

I don’t think WP_Query returns the meta fields for you as well. So you need to loop over the posts and run get_post_meta() manually. Assuming one office has at max one _octopus_id, you could write it like this: // here we will store the ids $octopiIds = []; $query = new WP_Query([ ‘post_type’ => ‘office’, … Read more

Array to string conversion on array_map

Look closely at $offices: array (size=500) 0 => array (size=1) ‘id’ => string ‘1382’ (length=4) 1 => array (size=1) ‘id’ => string ‘1330’ (length=4) That is not an array of IDs. It’s an array of arrays. $offices[0] is not ‘1382’. It’s an array. So implode() on $offices is trying to concatenate arrays, which is what’s … Read more

Only show size attributes in product box woocommerce when available

to test is the text is not empty, try that : function display_size_attribute() { global $product; if ($product->is_type(‘external’)) { $taxonomy = ‘pa_maat’; $text = $product->get_attribute($taxonomy); if (!empty($text)) { echo “Maten:”; echo ‘<span class=”attribute-size”>’ . htmlspecialchars($text) . ‘</span>’; } } // END if ($product->is_type(‘external’)) { } // END function display_size_attribute() {

WC_Customer delete function returns error

Welcome! You need to include ‘wp-admin/includes/user.php’ before calling wp_delete_user function. The reason is, it is an admin functionality and it is not available everywhere in code. In Your case, just put the following line of code at the very beginning of the function. require_once ABSPATH . ‘wp-admin/includes/user.php’;

Plugin development and composer

So, I want to find some solution where I can set only the composer.json file inside the plugin folder and after the plugin activation to pull and install the required SDK. That’s not how it works. Composer is a CLI tool that’s meant to be ran via CLI, and wasn’t designed to run in a … Read more

Basic wpdb update question

I think the line should be: $selected_candidate = $_POST[‘candidat’]; => $selected_candidate = $_POST[‘selectCandidate’] Btw. You are using “prepare” in the wrong way. You are not protecting yourself from sql injections, use it like this: $wpdb->query( $wpdb->prepare(“UPDATE pp_candidates SET candidate_approved = 1 WHERE candidate_ID = %d”, $selected_candidate));

How to define a variable already defined in a plugin function?

This is fairly easy. First, you need to use a child theme. See the following on child themes if you are unsure what they are or how to use them. https://developer.wordpress.org/themes/advanced-topics/child-themes/ The theme you are using uses pluggable functions which makes them easy to override. Note the function in the theme is written like this… … Read more

WordPress transient not working with WP Engine

So I don’t know why the return $cached_result; in the else, but if that’s intentional, then you should probably do: return json_decode( $cached_result, true ); Because you’re caching the response body (which is a JSON string) and you’re reading the non-cached result like so: $array = json_decode($result, true);. But if that return was a mistake, … Read more

Loop over Array and get the distinct ids

No, that’s because you are treating an array as an object and PHP doesn’t convert those types automatically. To get an individual element from an object you use: $my_object->Element1; To get an individual element from an array you use: $my_array[Element1]; You can even nest arrays. So if you have $my_array, where each element is another … Read more

How to add no follow to specific links?

The replace code is replacing the whole a element content with <a rel=”nofollow”>. Here’s the correction: I used (.+?) between <a and href” and before and after /go/pluto/ to the closing >. Then in the replace, we put $1 $2 $3 etc. to keep them and add rel=”nofollow”. You can check in this test, and … Read more