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

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() { $...
0
votes
1answer
21 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 ...
0
votes
0answers
27 views

Widget Array - How to use button to add element to array inside widget and update display? How to update? [closed]

I have this widget When we press "Add Scene" button widget assume will look like this... And here's form code: function form( $instance ) { $scenes = isset ($instance['scenes']) ? $...
0
votes
2answers
20 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 ...
0
votes
1answer
27 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/?...
0
votes
0answers
24 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' => '...
0
votes
0answers
35 views

WP query meta key is returning an array, how can I compare this to a date? [closed]

I'm using the ACF Multi Dates Field plugin with ACF to allow user to select multiple dates for an event. I need to compare the return value of the multi date plugin to the current days date. But the ...
0
votes
1answer
42 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( ...
0
votes
1answer
8 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( ...
0
votes
1answer
18 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 ...
0
votes
1answer
40 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 ...
1
vote
2answers
53 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, ...
0
votes
1answer
15 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 ...
0
votes
0answers
10 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 ...
0
votes
1answer
36 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'...
0
votes
1answer
18 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 ...
0
votes
0answers
13 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. $...
0
votes
0answers
38 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 ...
0
votes
0answers
60 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 ...
0
votes
0answers
24 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 ...
1
vote
1answer
40 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 ...
0
votes
0answers
21 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 = ...
0
votes
2answers
28 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( ...
0
votes
1answer
50 views

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

This has been cleared. Leave it cleared.
0
votes
1answer
13 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 ...
0
votes
1answer
34 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... ...
0
votes
0answers
13 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, ...
0
votes
0answers
40 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 ...
0
votes
1answer
31 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
92 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
21 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
20 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
30 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
18 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
56 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
21 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
63 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
46 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
25 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
44 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
269 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
31 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
12 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
101 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
19 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
27 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([...

1
2 3 4 5
15