Questions tagged [array]

An array (in PHP) is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.

Filter by
Sorted by
Tagged with
0
votes
0answers
15 views

Count comments made by certain user's role (count intersect array in php)

i created a code to display a table with columns containing: post date, post title, and number of comments of users with certain groups (actually certain meta data). But the following code only works (...
0
votes
1answer
19 views

How to print Array values of custom Fields Meta?

How to print array values for custom field meta. My code - <?php $item = get_post_meta($post->ID, 'occupationalCategory', false); ?> <?php print_r( $item[0]['occupationalCategory'] ); ?&...
0
votes
2answers
79 views

Search for a keyword across post types in a Gutenberg component

In a Gutenberg component I'm developing, I have a function that searches for a keyword across multiple post types specified in a constant: const postTypes = [ 'posts', 'pages', 'portfolio' ]; const ...
0
votes
1answer
15 views

Wordpress Include 'print_f' in WP_Customize_Control array [closed]

I have the following problem: I want to add print_f in an array in wordpress. printf( __('Option to share on %s', 'themename'), 'name') However, the following code does not work properly for me. ...
0
votes
1answer
19 views

Counting instances of words in the results of a post query

I'm way over my head with this one and wonder if anyone can shine a light on where I'm going wrong. I am grabbing some authormeta for the resulting posts of a query, and I want to tally up the number ...
0
votes
1answer
29 views

how to get users with usermeta include array of an array

i have a user_meta for users that them is array like below: user_saved_posts = [31289,31482,27641] and i want to get users that their user_meta include an item of an array like below: goal_posts = [...
0
votes
1answer
17 views

Taxonomy terms not properly displaying as array

I'm trying to get posts with custom taxonomies. I have this function below: public function get_job_categories_all () { $get_categories = get_terms( array( 'taxonomy' => '...
0
votes
1answer
41 views

Add taxonomy column with meta field (ACF) content

Trying to populate the column with meta field, this way (ACF): add_filter('manage_artist_custom_column', function ($content,$column_name,$term_id){ $term= get_term($term_id, 'artist'); switch (...
1
vote
1answer
18 views

how can i show only the parents in owl-carousel?

I have this code that shows all the posts in my post type (parents and children). the php is: <div class="owl-carousel owl-theme"> <?php $c=0; $...
1
vote
0answers
57 views

How to use $query->set with post__in?

I use the pre_get_posts hook to change the search results because I have a filter form. This hook gives me access to an already made $query object. This line does not work: $query->set('post__in', $...
0
votes
0answers
10 views

Display 1 custom post type by a custom taxonomy not working

So the idea here is I have multiple products (CPT) and a custom taxonomy named Feature. It's a radio button field with Yes/No option. I want to display 1 random featured product on front page. But ...
0
votes
0answers
17 views

How to make a front end fields from metabox

I want to clarify that I am not a specialist, my query is how to insert a metabox in the front end, specifically I show you the image: I want to do this: But actually I have this: Those are the php ...
0
votes
0answers
18 views

How to delete post meta array by value

I have three fields I am saving as an array to a custom post meta. Like such... <label>Member:</label><input name='cantcommit[mbr]' value='' /> <label>Arriving:</label>&...
0
votes
0answers
11 views

Order custom field values by popularity

I have two custom fields: "usp-custom-ticker" and "ticker". I want to combine them into one list (which I already successfully did with the following code): <?php $...
1
vote
0answers
22 views

Unset field from an array not working as expected

I'm trying to filter a custom options page from acf that is used to create menus based on items that are added on the backoffice, but I'm not being able to unset the fields when they aren't supposed ...
0
votes
1answer
21 views

sanitize_post() is not sanitizing Post Object

I wanted to sanitize a WP_Query post object without using foreach. I used this method: $args = array( // ... ) $data = array(); $the_query = new WP_Query($args); $data["post"] = $the_query-...
0
votes
2answers
91 views

Gutenberg: How filter blocks of a certain type with parse_blocks recursively?

I struggle with columns block in my plugin. I try to filter all blocks of the type "heading": $post = get_post(); $blocks = parse_blocks($post->post_content); $headings = array_values(...
0
votes
0answers
23 views

Creating an array from form inputs before it is posted to the options database

I am creating a plugin and I want to be able to have the user input a starting number and ending number from an options page. When they submit it I want to create an array of the numbers (example ...
0
votes
0answers
11 views

Output Term List and Respective Term Slug from Multiple Taxonomies

Complete original code renders 'category' terms with link. My modifications to the original renders 'category' terms with link but does not link out parent nor children of 'genre' (they render okay). ...
1
vote
1answer
57 views

Create shortcodes within foreach loop (using array)

I have a custom theme that includes several template parts. I intend to use theme template parts within theme files as well as using them as shortcodes. To create the shortcodes I am currently ...
0
votes
0answers
15 views

Save input and select field in a plugin as an array

So I have two settings fields (one input and one select) which are working perfectly. However I want to "merge" these two options to display them next to each other in one callback. I tried ...
0
votes
0answers
26 views

Query when is one or several values

I'm trying to make filter by querying different elements from a custom post type (stores) The problem is when I want to query the "styles", given that all stores have 2 or more instead of ...
0
votes
0answers
24 views

How to utilise multiple values from a single shortcode attribute?

i.e [test somevalues=1,2,3,4,5] First time poster and alsoa php newb, I'm trying to add a feature to a plugin but I seem to keep triggering a debug notice from wordpress. $somearray = shortcode_atts([...
0
votes
0answers
16 views

CPT Adding points on a ranking

I'm new to wordpress and php but trying to improve. I've already done my relevant search but I think I'm also lacking concepts. I have two CustomPosts cyclist and dateRace and i want to do is two ...
0
votes
0answers
26 views

Wordpress update databse table

Can anyone explain to me wpdb update database I would like to understand about $where (an array of field name). $table The table name. $data A PHP array where the keys are the columns and the values ...
0
votes
0answers
38 views

Wordpress, result array of 'post_name'

when I try to run this array it doesn't give me the exact results of the 4 slugs I want to get, but many more results come out. $slugArray = array( 'post_type' => 'post', 'post_status' ...
0
votes
0answers
24 views

Gutenberg does not render changes in array of objects meta

A post has a meta value which contains array of objects. Seems like the values printed in a loop in fields do not render a changes unless I send a new meta key with dispatch. This does not work, If i ...
0
votes
0answers
55 views

Gutenberg TextControl value from object in array - Value does not update to Attributes

I want to render controls from an array of objects. The controls render from default [{'question' : '', answer : ''}] , but the value does not update back to Attributes when I type in the fields. A ...
0
votes
1answer
22 views

wp_force_remove_style' not found

I have this error show up in my error_log. PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'wp_force_remove_style' not found or invalid function name in wp-...
0
votes
0answers
36 views

change permalink number

these days I wonder how I can change the final permalink number of my posts by +1, i found this code on the net, but it needs to be changed someone help me? // Get all posts $query = new WP_Query(...
0
votes
0answers
13 views

Retrieve all custom field values of a specific custom field metakey as an array, inside WP_Query

I'm building a function into a shortcode to retrieve information relative to a custom post. For the most part, I can retrieve everything I need with the following, despite (probably) not being the ...
2
votes
1answer
34 views

Show post only if match all categories

I have posts that have multiple different categories including a common category called "Videos", now I'm trying to show only posts that match with the all categories of the main post ...
0
votes
0answers
15 views

Help with get_post_gallery_images()

everyone. I'm trying to use get_post_gallery_images() to retrieve URLs to the images in a gallery in the post I'm using the function. I read that this function will return a string of URLs for the ...
0
votes
0answers
37 views

“WordPress database error: You have an error in your SQL syntax” when using array_filter();

I try to update WP database custom table with form data and everything is OK. BUT one error doesn't give me peace of mind. WordPress database error: [You have an error in your SQL syntax; check the ...
0
votes
1answer
15 views

PHP | left join avg query give me Array()

I'm trying to implement a query within my code that gives me the ability to calculate the average value between the ratings received and the number of ratings per post, and sort posts from the one ...
0
votes
1answer
40 views

WP Query by 4 different taxonomies

I need to make a shortcode that uses the values of four different taxonomies. I am trying to modify code that I have used to query attachments (in media) based off of multiple taxonomy terms, but ...
0
votes
0answers
21 views

How to use multiple (or array) values in $content of shortcode?

I have a shortcode that fetches some values, first_name, last_name and email from a remote database. I'm trying to write a shortcode that will allow me to print 2 or more of those values within output ...
0
votes
1answer
24 views

Trouble with serialized metadata

I've read about 20 different posts on this topic and I still can't apply the solutions to the problem I'm having. I'm very sorry for not being able to figure it out based on those answers, but I ...
0
votes
0answers
20 views

How to get posts by meta value as multi-dimensional array?

I know how to get posts by a specific post meta when the meta value is a string. $meta_query = [ [ 'key' => $meta_key, 'value' => $meta_value, 'compare' => '=' ...
0
votes
0answers
33 views

How can I show how much water got saved on this order (making use of the number of items bought) on a thank-you-page?

More detailed: I'd like to use the the number of items which were bought by somebody and multiplicate it with a number, to show how much water somebody saved. function random_message(){ $...
0
votes
1answer
64 views

Foreach loop inside an array_merge

I need to get a list of users display names in a dropdown menu. I have the query right, but I'm not sure how exactly to get my user foreach inside of an array. Here is the code I need to inject the ...
0
votes
0answers
86 views

How to exclude child categories from multiple parents in WP_Query?

I have some code <?php $exclude_category = [10]; $company_category_parents = get_categories( array('child_of' => 5) ); foreach ($company_category_parents as $...
0
votes
1answer
25 views

Access to numerically indexed array in wpdb Class and undefined offset

the following database call $einzel = $wpdb->get_row("SELECT t.id, DATE_FORMAT(t.datum, '%d.%m.%Y'), DATE_FORMAT(t.datum2, '%d.%m.%Y'), t.ueberschrift, t.uhrzeit, t.termintext, t....
0
votes
1answer
274 views

issue with if/elseif in_array inside foreach loop display only one post

I try to attribute a specific background-color to each post if one of categories of post corresponding to one category. My function works but is restricted to display only one post in result. If I ...
0
votes
0answers
9 views

Get only one array instead of multiple arrays with PHP

I'm trying to build one json object out of one array, but my loop seems to be building several arrays. This is what I'm getting: [{"basic_lease":"5209"},{"expanded_lease":...
0
votes
1answer
582 views

How to write PHP array to render JSON-LD Markup for Job Postings, with ACF

i want to add a dynamic JSON-LD (schema.org) for career posts in my wordpress page. I tried this code below. But i think i have some Syntax errors within the array. Maybe the "echo" is not ...
0
votes
1answer
22 views

how to separate an array into different arrays and save them into db?

I have a quick question, I'm developing a wordpress plugin and need some help I have the following array which I got in php from ajax: $array = [ "car_model_1=modelo 1", "...
1
vote
1answer
33 views

Display a CPT based on a metabox selection

I am trying to display multiple post based off a custom metabox selection. I am currently using CMB2 as my framework to display the CMB within the backend. The selection field which has an ID of ...
0
votes
1answer
78 views

What form should the $query media query array have for an Elementor page builder function? [closed]

I'm building a theme with the Elementor page builder and I want to add some CSS output to certain elements. I hooked into the parse_css function. I want to use the stylesheet::add_rules() function (...
0
votes
1answer
29 views

Adding an item to an anonymous array inside a filter?

I'm trying to add a user_role inside the ATUM stock management plugin. Currently it's only visible to admins, while I also want to add shop_managers. But I just can't succeed in adding it successfully ...

1
2 3 4 5
15