2022 Developer Survey is open! Take survey.

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
0 answers
11 views

Stuck at MultiDimensional Array

I am using to get values from array this code UPDATED CODE $specifications_group = $product->post->post_parent > 0 ? $product->post->post_parent : $product->post->ID; ...
user avatar
0 votes
0 answers
29 views

Custom Field: how to save array of multiple key-values in WordPress

I have this kind of data on my database: <wp:postmeta> <wp:meta_key> <![CDATA[property_icalendar_import_multi]]> </wp:meta_key> <wp:meta_value> &...
user avatar
  • 125
0 votes
0 answers
9 views

Sort query_terms_list for post_tags alphabetically

I have the following array that currently sorts tags by tag count and returns the tags with the individual tag count. I would like to keep the individual tag count but sort the tags alphabetically ...
user avatar
  • 7
0 votes
1 answer
17 views

Include current post into loop

I have a related posts loop ( in every single post page ) based on post title. source : https://wpza.net/get-related-posts-based-on-the-posts-content-in-wordpress/ But I also need to include current ...
user avatar
1 vote
0 answers
24 views

Populate dropdown with Child Pages based on Parent Page chosen

I'm trying to populate the Child Page dropdown with that of the selected Parent Page - If a specific Parent page is chosen it should fill the second dropdown with all Child pages listed under that ...
user avatar
  • 11
0 votes
1 answer
35 views

Custom archive page for custom taxonomy and pagination issue

so this is something I am trying to figure out for quite some time about my custom archive page for a custom taxonomy 'workplace'. There is many workplaces, and what i want is to display the products (...
user avatar
  • 16
0 votes
1 answer
19 views

update_post_meta() updating nested array in Multidimensional array with empty sub-array

How can i update/remove/empty a sub-array on user post submission in admin area? here ist the reference on how to update nested array i am using but it is not working if ( $post->post_type == '...
user avatar
0 votes
1 answer
11 views

List latest post for each tag with a category

I have a page where the latest posts are displayed from within a specific category. array( 'posts_per_page' => -1, 'post_status'=>"publish", 'post_type'=>"post&...
user avatar
0 votes
1 answer
15 views

Combine 2 arrays in a query parameter

I'm trying to exclude upsells using post__not_in but I already have a value and do not know how to combine the two. I tried this: 'post__not_in' => get_upsell_ids(), [get_the_ID()] But it is not ...
user avatar
0 votes
0 answers
36 views

Problem with inserting multiple images in gallery of each WooCommerce product programmatically

I am creating a script to programmatically add multiple images to the gallery of each WooCommerce product. The script works but only takes the first image, I'm having a hard time figuring out how to ...
user avatar
  • 1
1 vote
0 answers
84 views

Insert woocommerce products programmatically with featured image and gallery

I'm inserting WooCommerce products programmatically to the database, but I'm having trouble inserting and linking first image as featured image and multiple images for gallery assigned respectively to ...
user avatar
  • 11
0 votes
0 answers
26 views

Override a Post's URL with Advanced Custom Fields Function

I have a field on specific post pages which allows the user to create a new link to forward the user to a completely new URL (this is so it still appears within the filtering of Post Content and has a ...
user avatar
  • 1
0 votes
0 answers
16 views

Convert a column of a table containing an Array as response in HTML

I am trying to iterate through the following information saved in a table in my database: wp_table_log id_envio int(11) order_id int(11) fecha datetime request text response text ...
user avatar
0 votes
0 answers
24 views

Save / Update meta data as multidimensional array

I need some help with saving my meta data from a post. On the editpage I have the following input fields <input type="text" name="data[color][]" value="red"/> <...
user avatar
0 votes
2 answers
52 views

How to get the `comment_post_ID`?

I have extracted the reply emails. The original emails are saved as CPT and work as Tickets in my plugin. I want the reply email to go as a comment to the original email. for($j = 1; $j <= $total; ...
user avatar
0 votes
1 answer
34 views

get_the_terms, whether I should use string or array as the second parameter?

When I running Query Monitor on one of my page, I get a notice "Array to string conversion" for the following line: $terms = get_the_terms( $post->ID , array( 'product-categories') )...
user avatar
  • 41
0 votes
0 answers
21 views

How do I get specific readable results from this query and array results

I am running the following query to get an array of WP revisions which includes custom fields revisions. This seems to be working and spitting out the array and there are two values I am wanting to ...
user avatar
  • 1
0 votes
1 answer
38 views

last_name + first_name orderby with meta_query [solved]

I have small issue with orderby. I´m looking solution to orderby ASC (lastname + firstname) example: Selanne Andy Selanne Beeny Selanne Teemu But now it arrays something like this: Selanne Beeny ...
user avatar
  • 3
0 votes
1 answer
22 views

How to get the last category name of a child category?

there. I've tried tons of solutions I've found in this forum before asking this. It's kind of hard for me to understand the php sintaxe. I have no idea how to do this and i've been stuck for days ...
user avatar
  • 11
1 vote
1 answer
20 views

Sorting table function default

Trying to get this table to sort by default by "publish_date" Where can I add it? $transaction_params = array( 'posts_per_page' => $page_size, ...
user avatar
0 votes
0 answers
17 views

Sending simple variable on single page to WP JSON

I like to send specific data from a post to my JSON response in Wordpress. I like to send the output of the variable "hatus" to the JSON response, but it does not seem to work. <?php ...
user avatar
  • 287
0 votes
0 answers
46 views

Counting a WP_Post Object value in an arary, using a filter?

I am trying to check whether a post in the array is the first post with a certain array value. I have a code similar to the one below: Plugin code <?php function my_function() { $...
user avatar
  • 230
0 votes
1 answer
25 views

meta_query compare “=“ returns nothing when it seems it should

Trying to query based on form submission. One select on the form is built with: wp_dropdown_categories( 'name=specialty&taxonomy=specialties&orderby=name&show_option_none=Select a ...
user avatar
  • 1
0 votes
2 answers
74 views

Tax query with multiple terms in pre_get_posts

I am trying to use a tax query in my pre_get_posts function. All is working but not when the array has multiple IDs. Let's say my URL looks like: ?listing_cat[]=1&listing_cat[]=2 Now I am trying ...
user avatar
  • 230
0 votes
1 answer
49 views

Create an array with all the links of the years' archive (of a custom post type)

I have a custom post type called "papers" and I need to create an array with all the archive links per year that exists. Something like: array ( [0]=> 'http://www.example.com/2021/?...
user avatar
0 votes
0 answers
33 views

Merge get_comments & get_posts into a single query

On the static home page, I want to display the latest site activity sorted by date in a social network style. I get the comments: $comments_query = get_comments( array( 'status' => '...
user avatar
  • 5
0 votes
1 answer
49 views

Display just one post from a loop of 5 posts?

Let's say I have this Query to which I fetch all my WP posts and then use PHP to filter out even further: <?php $posts = get_posts(array( 'tax_query' => array( array( ...
user avatar
  • 203
0 votes
1 answer
14 views

Order users by random not working?

So I'm trying to list my wordpress user id's each time in a random order. Right now I have this, but for some reason, 'orderby' => 'rand' is not randomizing the list. <?php $args = array( ...
user avatar
  • 203
0 votes
1 answer
30 views

Redux option doensn't seem when include from functions.php

When I write redux framework option into header.php, it is shown.However when I add the same php code into a php file and include the php file from functions.php, it doesn't seem. header.php: <?php ...
user avatar
0 votes
1 answer
51 views

Get an array of the number of post per year of a custom post type (Wordpress)

I have a custom post type called "papers", and, to feed a chart, I need an array of the number of posts per year that have posts. I've tried with wp_count_posts() but it just give me the ...
user avatar
1 vote
2 answers
157 views

'orderby' => 'rand' alternative for better performance?

I have been told that using this in the array: 'orderby' => 'rand' will cause this: Ordering by random is extremely expensive to query, involving creating temporary database tables, and scans, ...
user avatar
  • 203
0 votes
1 answer
78 views

Compare two meta key values against each other inside the get_posts array?

I'm banging my head to the wall all day trying to figure this out. I have two meta keys a1 and a2 with numbers inside. I'm trying to show posts that are a2 > a1. In a nutshell, here's what I'm ...
user avatar
  • 203
0 votes
0 answers
12 views

How can I update this array built from post meta data?

I'll try and do this as concisely as I can, apologies if it's not! I have two custom post types: 'Psychic' and 'Review'. There can be several 'Review' posts for a single 'Psychic' post. I link the ...
user avatar
  • 297
0 votes
1 answer
43 views

How to set if meta_value is lower < than other meta_value in a get_posts array?

So I'm building this post query array: $posts = get_posts(array( 'author' => $publisher_info-ID, 'post_type' => 'post', 'posts_per_page' => 150, 'meta_query'...
user avatar
  • 203
0 votes
1 answer
44 views

How to say if meta_value is greater than 0 in an array?

Right now I have this: $args = array( 'meta_key' => 'userfunds', 'meta_value' => '0', ); Basically this will show users who have exactly '0' as meta_value. How do I say that ...
user avatar
  • 203
0 votes
0 answers
17 views

How to display user_meta array as a table?

Ok, so I'm building a "Transactions" table for a user using user_meta array. I'm new to this and trying to figure things out. Basically, in practice I know how to store array to user_meta. $...
user avatar
  • 203
0 votes
0 answers
39 views

What format is this and how to get value "lal" and "pila" from it

[2] => a:2:{i:0;s:3:"lal";i:1;s:4:"pila";} saved by wordpress function as an array add_post_meta($contestid, 'suraj', array('lal','pila')); and retrieved by the function ...
user avatar
0 votes
0 answers
272 views

How to access specific Element in Nested JSON Array in PHP?

I have a very large JSON file output from an API which has so many nested child elements, I have been trying to figure out a way to access only specific ones but it has been a total chaos and I ...
user avatar
0 votes
0 answers
29 views

Combine relationship posts with existing wp_query

So I am building a query, and I wanted to see if someone can assist me on a special attempt to infuse two queries. So here is what I'm attempting to do: Check if we have any relationship posts, which ...
user avatar
  • 1
2 votes
1 answer
339 views

Passing array of strings to a SQL statement in a WordPress plugin

I have an issue with passing an array of strings to a SQL statement in a WordPress plugin, because the prepare method adds a backslash before each apostrophe. // I have an array of strings. $the_array ...
user avatar
0 votes
0 answers
57 views

wpdb Insert unknown post data dynamic foreach loop

I have this old function which I would like to use in WordPress. public function database_insert( $table, $data ) { $data_key = "("; $data_value = "("; $i = ...
user avatar
0 votes
2 answers
41 views

How to use two meta_compare in an array?

I want to use two meta_compare in an array. // get posts $posts = get_posts(array( 'post_type' => 'post', 'posts_per_page' => 150, 'meta_query' => array( array( ...
user avatar
  • 203
0 votes
1 answer
51 views

Any idea how to get something like this to work? [closed]

This has been cleared. Leave it cleared.
user avatar
0 votes
1 answer
23 views

in_array not working on dev server but works on localhost

I've written a loop which works on my local machine but not on my dev server. My dev server is running PHP 7.4.13 and my MAMPRO is running 7.4.12. The dev server code displays nothing and with no ...
user avatar
  • 125
0 votes
1 answer
105 views

Warning: in_array() null given in PHP function

I'm building a metabox gallery in Wordpress for a specific page template. I have the following warning notice in the dashboard: Warning: in_array() expects parameter 2 to be array, null given in... ...
user avatar
0 votes
0 answers
22 views

Display related products by matching the product title to any tags of the current article

How do I display products in a custom post type single page by matching the queried product title to any tags of the current article? Below is my code which seems to output some random product names, ...
user avatar
  • 125
0 votes
0 answers
44 views

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

I've written code to display a table with columns containing: post date post title number of comments of users with certain groups (actually certain meta data). The following code only works ...
user avatar
  • 1
0 votes
1 answer
83 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'] ); ?&...
user avatar
0 votes
2 answers
132 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 ...
user avatar
  • 1,617
0 votes
1 answer
30 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. ...
user avatar
  • 3

1
2 3 4 5
15