Questions tagged [php]

For questions about the server-side programming language that the WordPress core, plugins and themes are written in. Questions about using PHP outside a WordPress context are off-topic but might be asked on Stack Overflow.

Filter by
Sorted by
Tagged with
-1 votes
0 answers
12 views

How to avoid, skip or fix "Uncaught Return type of Requests_Cookie_Jar::offsetExists($key)" during phpunit

Phpunit 9.5.21, Ubuntu 22.04, PHP 8.1.2 I can not unit test my plugin locally on Ubuntu anymore because the shipped php version is 8.1, and it fails. in /home/username/dev/wptests/wp/wp-includes/...
user avatar
0 votes
0 answers
9 views

Get the list of post categories

How to get the list of post categories I have this but it returns only one category and the entire list? $categories = get_categories(); foreach($categories as $category) { echo 'term_id) . '">' ...
user avatar
0 votes
1 answer
15 views

Need help with Deprecated: Non-static error when update PHP 7.4 -> 8.1 with Dyad 2 theme

I have two Wordpress sites with theme Dyad 2 https://wordpress.com/theme/dyad-2 I need to upgrade from PHP 7.4 to 8.1, but when I try I got four "Deprecated: Non-static" errors. I managed to ...
user avatar
  • 1
0 votes
0 answers
14 views

ACF repeater values in get_posts [closed]

i display custom post types that are connected in another custom post type, everything works fine, but now i want to display some data from CPT repeater fields. Not working part starts "if( ...
user avatar
  • 1
0 votes
1 answer
20 views

404 page is not the same when using PHP code in functions

Based on a condition I want to show 404 page and I have the following PHP code in functions.php function wpse91900_force_404(string $template): string { global $wp; $current_url = home_url(...
user avatar
  • 175
0 votes
0 answers
27 views

PHP code snippet to remove microdata

A plugin I am using is adding "Person" microdata to my pages eg https://seoace.com.au/content-and-analysing-competitors/ which I would like removed. I am looking for a PHP code snippet that ...
user avatar
0 votes
0 answers
18 views

Wrap title and excerpt in a div (latest posts block)

I am trying to achieve to following the desing with the latest posts block: On the left is the features image, on the right the categories, title, excerpt and a read-more button. This is what I got ...
user avatar
  • 1
-1 votes
0 answers
12 views

Add calculated fees analytics [closed]

tell me where and how to add your additional fee calculation point By analogy with the tax
0 votes
0 answers
10 views

Want to unrestrict plugin block

The plugin I am using restricts using its block on certain post types. I would like to unrestrict it. I remember it being easy in WordPress at one time, but now I cannot find where that is with the ...
user avatar
0 votes
1 answer
63 views

How to set variables with AJAX request to use in another function in WordPress

$.ajax( { method : 'POST', dataType : 'json', url : my_var.ajaxurl, data : { foo : foobar, ...
user avatar
0 votes
0 answers
6 views

Deleting expired session tokens in Wordpress

We have about 40k users in our Wordpress database. There are only a handful of these that do not have expired sessions. Is there some built-in facility in Wordpress for deleting these sessions on an ...
user avatar
0 votes
0 answers
21 views

Set Core Block Attributes in Innerblocks template via PHP [closed]

I am hoping to make a custom <Innerblocks /> template for my custom block using some of the core blocks. The structure is meant to be: Columns Column Heading Paragraph ...
user avatar
  • 468
0 votes
1 answer
15 views

how to get wordpress page url php code [duplicate]

So am trying to get wordpress current page url in the header. I tried below code but not working, Please it urgent. your can see my client current music theme. $current_url = home_url($_SERVER['...
user avatar
0 votes
0 answers
24 views

Getting URL GET parameter with Code snippets and storing it in database?

I need to extract specific parameter utm_medium that is passed as parameter to all pages or posts on my WP site and store it in database. So every time someone visits my post I must collect that ...
user avatar
0 votes
0 answers
15 views

How to access all meta data for RSS feed?

I am working on pulling a RSS feed from another WP site. I need some flexibility with where to display this within the site so I have set up a Shortcode for it. However, I can't seem to get the ...
user avatar
  • 125
0 votes
0 answers
20 views

Why Is Number of views on wordpress single post wrong?

Hello wordpress devs and community. I have a concern about the number of views showing on my wordpress posts, its wrong. I used this code in functions.php; function gt_get_post_view() { $count = ...
user avatar
0 votes
0 answers
11 views

Search AJAX Filters - Multiple Query Loops Into One Loop (Optimization)

I followed a tutorial on how to make AJAX filters and I have a concern about the loops. I am using bootstrap accordion to display the search ajax filters (ex. https://prnt.sc/gxrJE9_GocOl). I am ...
user avatar
0 votes
0 answers
8 views

Search Ajax Call - Use Form Data in Response

I have an AJAX call and I am worried that I am not using the serialized form data in the response properly so I get the value from ajax filter inputs (i.e.https://prnt.sc/gxrJE9_GocOl) but I am doing ...
user avatar
0 votes
0 answers
18 views

Group episodes by seasons

So i have 2 custom post types, Shows and Episodes. I want when im on example.com/show/better-call-saul, to group episodes by seasons for example: -Season 1 .Episode 1 .Episode 2 .Episode 3 -...
user avatar
0 votes
1 answer
13 views

WP_Query: How to get results from both meta_key options?

I have the following WP Query: if(isset($_GET['scope']) && !empty($_GET['scope'])) { $scope = $_GET['scope']; } else { $scope = ''; } $foo = new WP_Query([ 'post_type' => '...
user avatar
0 votes
0 answers
13 views

Inline CSS header style priority function.php Child (no enqueing I think)

I am webdesigner that knows some basic CSS and HTML. I never worked with PHP and I don't know how to handle this problem but I think it's fairly easy... Well I hope. This is the code: <?php if ( ! ...
user avatar
0 votes
1 answer
14 views

wp_set_post_terms doesn't allow to manually add new terms [closed]

So I'm creating a function which based on the selected category for the post, it automatically adds terms (tags alike) to that post. It works fine, the problem is now the post has those terms and if I ...
user avatar
0 votes
0 answers
9 views

Display Post Title From Select Choice Loop in Advanced Custom Fields (ACF) - Wordpress

Dear Wordpress Developer, I have custom post type (CPT) and the name is Programs. Inside the post type admin, I only give the title input and ACF "Select" Field Type. From all ACF tutorial, ...
user avatar
  • 5
0 votes
1 answer
45 views

Warning: Attempt to read property "term_id" on int - Woocommerce

I would like to create a condition to manually hide product categories within the shop. I already started from a code base but I am trying to understand why if I put the is_product_category() ...
user avatar
  • 23
0 votes
1 answer
15 views

get_page_by_title() doesn't return the post object if the title has inverted comma (')

The question is self-explanatory. I have tried these so far. I have a post named John's Test with post id 1. In single.php, I tried, $extraPostID = 1; $extraContent = get_page_by_title(get_the_title($...
user avatar
-1 votes
0 answers
14 views

Display the number 0 to the place of nan [closed]

this is my code <?php $sql = $wpdb->prepare( " SELECT meta_value FROM {$wpdb->prefix}commentmeta INNER JOIN {$wpdb->prefix}comments ON {$wpdb->prefix}commentmeta.comment_id = {$...
user avatar
  • 1
0 votes
1 answer
16 views

Split have_posts() by two columns [closed]

I need to divide into 2 columns this loop. For example, 4 elements will go the left column, and the remaining 3-4 will go to the right column. <?php global $wp_query; $args = array(...
user avatar
0 votes
1 answer
11 views

HTML dropdown setting not showing last saved value in the database

I want a select-dropdown field to display the last saved option in the database; I started with this video from YT, https://www.youtube.com/watch?v=hbJiwm5YL5Q&t=3969s and got as far as 1:05:00 ...
user avatar
0 votes
0 answers
31 views

Show ranking based on post id

I created a rating for my site with this code, now it shows all the ratings for all posts and I want to show the number of ratings based on the post ID. comment.php <div class="custom-comments&...
user avatar
  • 1
0 votes
0 answers
16 views

Filter wordpress query by numerical order arguments

I have some programs that go according to the day but I want it to be filtered by custom field such as menu_order, that is, by numerical position through ordernum that I can give it This doesn't show ...
user avatar
0 votes
0 answers
41 views

orderby meta_value_num is not working, giving default order

I am trying to order my posts by a meta value so that I can show the most popular posts. But it is returning the latest posts instead. //WordPress loop for the custom post type $popular_args = ...
user avatar
0 votes
2 answers
36 views

wp_mail vs mail functions and header arrays

I've been having issues using wp_mail and mail functions in an application when specifying header elements in the function. I usually set up the header as an associative array, as in $mailheader = ...
user avatar
0 votes
1 answer
64 views

Custom map_meta_cap filter does not return ['do_not_allow']

I have created a custom role that only has access to certain pages and their children/parents. I have used map_meta_cap filter to solve this. However even though it goes through my function correctly ...
user avatar
  • 3
0 votes
0 answers
21 views

Creating New Dynamic Fields for a Certificate (Number Generation, Code Referencing, and more)

I'm making a certificate that's supposed to autogenerate and involves the need for multiple dynamic fields. I have everything else finished but I have difficulty trying to create 3 dynamic fields. ...
user avatar
0 votes
1 answer
11 views

How to show upcoming events according to start date field

I am trying to show upcoming events. I have created a custom post type "event" in wordpress. and by using ACF plugin i have created date field for every event. now i want to show upcoming ...
user avatar
0 votes
1 answer
28 views

Understanding webhooks

I'm kinda new to this part of programming, and I find it really confusing. I have a script that makes some contact with a third party api. It basically adds a customer to their data. What I heard is ...
user avatar
0 votes
0 answers
25 views

PHP: $_SESSION destroyed after page reload for my custom session

I have develop a plugin for customer portal. For check login I have use custom session. Few month ago I have face this issue which create for session_start() function and I have already fix this. Now ...
user avatar
0 votes
0 answers
21 views

Some problems in custom widget

I made a custom widget for my template, which has an image upload section For the first time, I upload an image, it displays correctly, without any problem, but when I want to change the image, it ...
user avatar
  • 1
0 votes
0 answers
21 views

Searching a tab/space delimited text file based upon form criteria and returning a 'record' into a word press results page

This is my first foray into turning a current perl (.pl) script into a bit of code within WordPress. We're looking to migrate this process/page which resides on an old web server into WordPress. ...
user avatar
  • 1
0 votes
1 answer
13 views

if custom field doesn't exist, use post thumbnail instead, as image background

I am trying to modify a code in my theme, but I only partially succeed. I need a working condition, if a custom field is not present, to use the post thumbnail instead, as the background image. if the ...
user avatar
  • 167
0 votes
0 answers
19 views

Call a function in functions.php from within <script> tags (JS)

I have a pretty simple problem (I think) which I can't find an answer to. The setup is pretty basic. I have a function which is in functions.php: function function_A($variable) { return $variable +...
user avatar
  • 111
0 votes
0 answers
12 views

Restrict post to current user in postmeta

i hope someone can help, i'm have not php skill, try with some sample without success. i have a CPT with metafield "email" where stored user email . does its possible to restrict post url ...
user avatar
  • 1
0 votes
1 answer
29 views

Wp Query : Order by distance lat,lon

I'm new to this forum, sorry in advance :) I have a problem with my display of my posts Let me explain ^^ I want to perform an orderby => '$distance' and display the posts accordingly. $lat2 and $...
user avatar
0 votes
1 answer
34 views

Displaying images outside the content

I am trying to achieve to following design: This is what I got so far: I'd like to have the bottom images as in my design example. This is, how my single.php looks like. I just can't find a solution ...
user avatar
  • 1
0 votes
1 answer
26 views

how to Update 15k products on plugin activation with meta_option

We need to update about 15.000 products with a meta_option after a plugin gets activated or after a plugin gets installed. However, our code does not execute on all products, though the plugin ...
user avatar
  • 149
0 votes
0 answers
16 views

WordPress Conditional / Multiple Taxonomy Query

I am trying to create a custom WordPress taxonomy query with multiple but conditional statements. However I am having issues when more than one taxonomy query is added to the statement. $tax_query = ...
user avatar
  • 1
0 votes
1 answer
12 views

change the default order of posts only for specific categories

I want to change the default ordering for posts, to last modified date, but only for certain categories pages (when visiting certain category pages) I have this function code, which is working, but I ...
user avatar
  • 167
0 votes
1 answer
21 views

Admin submenu issue with PHP not detecting two strings as equal

I am adding a submenu page as follows: add_submenu_page( $slug, __('Categories','acs'), __('Categories','acs'), $cap, 'edit-tags.php?taxonomy=acs-field-group-category&post_type=acs-field-group' ); ...
user avatar
0 votes
0 answers
14 views

How can I modify this code to make the search box include tags and meta

How can I modify this code to make the search box include tags and meta I would like the search in same box if($_GET['s'] && !empty($_GET['s'])) { $text = $_GET['s']; } if($_GET['type'] &...
user avatar
0 votes
0 answers
14 views

Validating an email input from form field before submit using JQuery, AJAX, and PHP

I have a form and one of the fields is an email with id email and after the user inputs their email and clicks outside the field, I wish to get the value of the email and then use ajax to pass that ...
user avatar
  • 1

1
2 3 4 5
203