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
0 votes
0 answers
13 views

How can I change the location where the custom field is displayed in the Quick Edit tab in WordPress

That's my situation right now: I want to display my "Artist" custom field under the "Slug" field, with the same HTML structure. But how? Example: The following code may help: // ...
  • 1
0 votes
0 answers
104 views

Show Login Errors In Wordpress/Elementor (Code "works", but breaks site)

I customized my WordPress/Woocommerce account pages using Elementor and now they don't show error messages when users enter the wrong password, etc. I found this tutorial online that worked nearly ...
4 votes
1 answer
221 views

How to enable REST API on custom post type without Gutenberg?

I understand that you have to enable the REST API in order to use the Gutenberg block editor, because Gutenberg relies on it; however, I want to use the Classic Editor for a custom post type and still ...
0 votes
0 answers
14 views

How do I organize posts based on their taxonomy?

I have a huge assortment of posts. They each belong to a taxonomy (let's say Taxonomy 1, Taxonomy 2, Taxonomy 3, and Taxonomy 4). On the page where they are displayed - I wanted them to be displayed ...
  • 1
0 votes
1 answer
225 views

Use of undefined constant issue

I have the following warning notice from my functions.php file: Warning: Use of undefined constant ENVIRONMENT - assumed 'ENVIRONMENT' (this will throw an Error in a future version of PHP) This is ...
0 votes
0 answers
26 views

How can I trim /page/ URL with PHP in Wordpress

Let me explain the situation to the best of my abilities. I'm using "?orderby=date&order=ASC" and "?orderby=date&order=DESC" which works fine. If the user is in domain.com/...
  • 25
0 votes
1 answer
28 views

How to sort wordpress posts by selecting a year from a drop down?

First of all, know that I'm just a beginner. Now that we got that out of the way... I've created something like this: <li class="dropdown"> <...
  • 25
0 votes
2 answers
124 views

How do i set global variable in a function in wordpress functions.php

Please vet this code and help me with how to declare '.($a['link']).' variable such that i can echo its content in single.php function mp3_download_link_att($atts, $content = null) { $default = ...
0 votes
1 answer
172 views

Convert custom field date format to "Wordpress default"

Hello ladies and gents, I'm using F j, Y (e.g. December 28, 2022) as default date format on my site (set in the admin settings). I have an event custom post type with an event_start_date custom field. ...
  • 17
0 votes
2 answers
25 views

inner-wrap div pushing custom table far down on page

I am working with code in a custom child-theme. My goal is to pull data from the wpdb and display it as a custom table. I have created and populated the custom wpdb table with the relevant data, and I ...
1 vote
1 answer
31 views

wpbd to connect to a VPS mysql database

I need to connect to a external database on my wordpress site but this database is on a VPS so I have the SSH Hostname, SSH username, SSH password, MySQL HostName on the VPS, MySQL port on the VPS, ...
  • 129
1 vote
0 answers
28 views

use wpdb object on other file

I need to connect my wordpress site to another database that is stored on a VPS, I also want to use this connection to query data and show it on my wordpress site, I see that I can connect to the ...
  • 129
0 votes
1 answer
16 views

orderby property of query on pre_get_posts returns incorrect value

I am attempting to implement some custom sorting logic for a column but are facing issues in the pre_get_posts hook. The value of the orderby property on the query is not returning the value ...
0 votes
1 answer
146 views

Remove Woocommerce product from cart with ajax/fetch

I have a problem with removing products from the cart in Woocommerce and I think it has to do with WC_Cart::remove_cart_item. I only get these error messages: POST http://localhost:3000/esport/wp-...
  • 3
0 votes
0 answers
17 views

Real estate schema markup not showing up on Rich Results test

I am not very techy, but I am trying to add schema markup to real estate listings automatically. The site is built using MyHome theme. Here is an example of a listing that I want to add schema markup ...
  • 13
0 votes
1 answer
36 views

How to get URL param for pagination in shortcode?

I have made the shortcode which displays data from database. There are so many rows and so I made pagination. But I can't get the URL param which means page number. <?php /** * Plugin Name: ...
  • 1
1 vote
1 answer
36 views

add_post_type_support but for front_page only

I want to enable excerpt for pages, but for front_page only. Using add_post_type_support('page','excerpt') enables it for all pages, since the first argument is $post_type. How can I narrow down it to ...
  • 13
0 votes
1 answer
34 views

How do I unset category from a product in wordpress by code

I would like to take it out a category from a product. If I want to insert a category I use: $categories = array(1, 2, 3); // Categories IDs wp_set_post_terms($product->ID, $categories, '...
0 votes
1 answer
44 views

How do I call an action hook into wp_ajax hook callback function

I have to trigger an ajax call based on a custom field changes on checkout form which is to add a discount. But if I call the hook to add discount into subtotal of the cart it does not do anything. ...
  • 44
0 votes
1 answer
39 views

Remove content links (internal and external), but exclude post at specific categories

add_filter('the_content', 'removelink_content',1); function removelink_content($content = '') { preg_match_all("#<a(.*?)>(.*?)</a>#i",$content, $matches); $num = count($...
0 votes
0 answers
51 views

XML WP_Query problem in PHP 8.0 and 8.1

I have a strange problem. In PHP 7.4 my script for generating XML for other comparison site worked well, but after upgrading PHP to 8.0 it doesn't work anymore. In sandbox I got these errors: Fatal ...
  • 1
0 votes
0 answers
33 views

How do I get a function to work in single.php

I have a code. add_action( 'init', 'njengah_change_post_date_programmatically'); function njengah_change_post_date_programmatically(){ $time = current_time('mysql'); wp_update_post( array ( ...
  • 3
1 vote
1 answer
39 views

ajax problems on loading page [closed]

I wrote a code that when a user click on a button. contents will be displayed via ajax in wordpress. I used wp_ajax_{action} and wp_ajax_nopriv_{action}. when I load the page ajax run without any ...
  • 46
0 votes
0 answers
29 views

I want to lists posts in wordpress to nearest location entered by the user

I have created a custom post type of (e.g:) doctor, have search input on the front-end and integrated the Google Map API. I want the search to look for the nearest location under the given search ...
0 votes
0 answers
16 views

How to change and edit users according to the extension in the URL

I built a nice system that simulates a "battle" when a certain button is pressed, it updates the users' data accordingly, at the moment it works on one step and it is built in a plugin, I ...
0 votes
1 answer
41 views

understanding wp_next_scheduled

I have a function that I've been attempting to get to work with wp_schedule_event. The function sends a notification to the admin. I see the event get added to the wp cron event list, but it never ...
  • 1
0 votes
0 answers
11 views

How to add a static image inbetween the product tiles on main shoppage woocommerce?

This is the first time i'm asking for help online so keepin' my fingers crossed. I was wondering if it's possible to add an ( static / clickable ) image inbetween the products on my main woocommerce ...
0 votes
1 answer
61 views

How can I get values from a custom post type depending on where I click on my SVG map?

Here's what I would like to achieve (desktop only): https://www.icifaubourgboisbriand.com/en/stores/ When I click on my SVG map, I would like to display an information card for each store. I have ...
0 votes
0 answers
34 views

Dynamically added text at bottom of article - non searchable by PHP code

I need to move certain articles on my website, all of them, to another unique category. I am using specific phrase which is at bottom of every article, but after code execution, only two articles are ...
0 votes
0 answers
55 views

Custom form that stores data in mysql database

Im currently building a website that allows a user to rent a boat rack but they need to be in the town in order to rent. I want to know how to create a form that allows the user to input their address ...
  • 1
2 votes
0 answers
25 views

Creating a table via dbDelta

I'm trying to figure out exactly how to create table structures in databases correctly, and after doing my research I'm left with a couple of questions that I can't find an answer to: In MySQL, there ...
  • 21
0 votes
0 answers
11 views

$wpdb how to make a record lookup

I have made a lookup form, where 2 inputted values, Selecting a Class, and Date, are prompted. Once the values are selected, then the First and Last names matching the records will be displayed. I ...
0 votes
0 answers
26 views

REST API custom endpoints for metaboxes

I have a three metaboxes connected to my custom post type "cpt-project". I would like to fetch the data to show it in the JSON using the REST API. I understand that I have to create custom ...
0 votes
0 answers
21 views

Save Edit button then disabled readonly metabox

Hello I am just starting out with php and I have managed to get a repeatable metabox and managed to add a 'Save' button which saves the input meta data to the database which works, how can I change ...
0 votes
0 answers
13 views

Posts in Admin only display 1 Post instead of all Post in admin area

Hi everyone, I am using M.E calendar plugin and i have published more event but in admin section showing only 1 post in all event area. As you can see screenshot below
1 vote
0 answers
36 views

How to get meta box labels?

I know how to add a meta box, and I know how to retrieve meta box values. That's not what I need; I just want to clarify that first. What I need is to get meta box labels by id. I am adding links to ...
0 votes
0 answers
33 views

How to change wp-admin and wp-login urls

I need to have a custom login url for a wordpress website that will use an headless theme to show a registration form. I've tried using the login_url filter but the result isn't really what I was ...
  • 1
-1 votes
1 answer
26 views

Make plugin admin page visible to other roles

I have created a plugin that I want users with the role of 'Editor' to be able to see and use in their admin panel.Currently, only administrators can see and use this plugin. I believe it has ...
-1 votes
1 answer
38 views

Option value not getting updated until page refresh in WordPress

I am building my WordPress plugin. There, at first I am using a checkbox, and then updating the value from the checkbox (yes or no) in the Database. Then, from later on I am fetching the value form ...
0 votes
0 answers
25 views

How to get data (not value or name) from radio options to POST to database

I have a set of options that are generated based on database count. For example, if a group has 4 members, 4 radio option pairs of yes and no will show: Name 1 - Attending? Yes / No Name 2 - ...
  • 145
0 votes
1 answer
24 views

Best way to delete/don't load a .php file?

In my theme files, I have a footer.php file that I can delete with no repercussions because I am using something else. What is the best way to delete/don't load that .php file? Until now I'm deleting ...
  • 1
0 votes
0 answers
33 views

There's a 0 adding to the value on multiple post type

I was wondering where did the "0" came from here: I have a query with multiple post type but when I tried to echo the value from those post types it adds '0' to the value. how will I fix ...
  • 13
0 votes
1 answer
27 views

Can't send form data to wpdb when URL has query string

I have a table called wp_invites which contains a list of invitees. This table contains a column called reference, which is added to the URL as a query param in order to customise their invite (i.e. ...
  • 145
1 vote
2 answers
36 views

Edit Error Page style

I have an faiulure page https://www.---.com/app/wp-comments-post.php Is there a way to edit the grey background and change it to white? The style is automatically inserted into the page. I've been ...
  • 15
0 votes
0 answers
38 views

Add default block css when the block has been added with php?

I have made a shortcode that adds a default block (eg. Cover) using php so that it can contain dynamic content. This works fine except that wordpress doesn't know to add the css for that block type. ...
0 votes
0 answers
26 views

Frontend redirect after delete post in wordpress

I'm using the following link to delete a post in the frontend of wordpress: function wp_delete_post_link($link = 'Delete', $before = '', $after = '') { global $post; if ( $post->post_type == 'page' ...
  • 1
-1 votes
1 answer
30 views

How to pull the current user's email and insert into a script placeholder?

I am using an affiliate tracker called Rewardful, and it requires me to pass the users email to this script <script> rewardful('convert', { email: 'email@goeshere.com' }) </script> The ...
0 votes
2 answers
95 views

Add a custom user meta data on registration based on user email

I am looking for a function to fill a user meta data automatically when they register. In the registration form we ask for user email. Once they validate their registration, we want to get that value ...
  • 3
0 votes
0 answers
27 views

ACF Image Alt Tags not loading Wordpress library meta's alt tag

I'm looking at trying to pull the alt tag from the standard Wordpress image library to display for images which are on a site using ACF. Previously the client's site had hardcoded alt tags which were ...
0 votes
0 answers
13 views

Selected dropdown option is not getting saved in the DB [duplicate]

I am building a function within my plugin where I have the list of available pages being displayed. What I want is for whenever a user selects a page from the dropdown, it should save the slug of the ...