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

How can we get this dynamically as this folder may not be by the same name always → wp-admin

action="/wp-admin/admin.ajax.php?action=slb_save_subscription" The above is a part of the code in WordPress, but I have read somewhere in the past that these folders can be changed. How can ...
0
votes
1answer
15 views

Ttle color based on category wordpress [closed]

I need to set post title bg-color based on category color. I have custom made WordPress template (nes blog) and I have colored category tags (sport- green, politivs - red,...). Now I need to set up bg-...
0
votes
1answer
30 views

AWS Lightsail Wordpress - connect to database on instance using mysqli

I have a wordpress website hosted on AWS Lightsail. On that website, I would like to use a shortcode to retrieve data from a database using mysqli. However, everytime the script that connects to the ...
0
votes
0answers
30 views

User meta needed in query is serialized - how to unserialize safely?

I'm a complete newbie to php, and I'm trying to use a function suggested by FacetWP to pre-select the post results shown to users. (I'm using this method, rather than pre_get_posts as I want users to ...
0
votes
2answers
21 views

How to use a custom hook

I try to create and run a custom hook on my Wordpress site. In the header.php file I used do_action('somestuff'); On my home.php and page.php I does the add_action like add_action('somestuff', '...
0
votes
0answers
20 views

PHP calling AJAX function that relies on passed PHP function values not working

In reading I am not sure if the issue below could have something to do with needing a custom wordpress ajax handler? All of these functions are inside my functions.php file. I have a couple of PHP ...
0
votes
1answer
24 views

How to show childs of certain custom post type in option list?

I have a custom post type and each post in this custom post type has many childs. I have a code that show every child that is child of the parent in child's page. (parent: post 1 , childs: sub1-post, ...
0
votes
0answers
15 views

Get attribute label on cart page Woocommerce [closed]

Issue/Desired Result I want to get the attribute_label on the cart page of my Woocommerce store, for example, 'Size'. My current code is giving me the slug, for example, 'Attribute_size'. How can I ...
0
votes
0answers
13 views

PHP issue passing results of variables from one function to another in same file but works on other pages [duplicate]

I am having an issue accessing my global variables inside the same file where the variables exist. However, they work just fine when I call the same variable in other files. To call the variable in ...
0
votes
1answer
59 views

Changing site identity logo with ACF options fields [closed]

I'm building an options page with ACF and I want the user to be able to update Site info via that menu. I'm able to update blogname and blogdescription with below method, but I don't really even know ...
0
votes
0answers
13 views

Disable customer Login [closed]

I'm looking for a way to disable the login but only for customers. I know I can deactivate their accounts but I need to do that in bulk. Thanks in advance!
0
votes
1answer
19 views

Short code template + ajax

I am doing a simple page that would work a single page inside Wordpress using Ajax. So to do this, I create a template page with a short-code in it. But the thing is that I really can't do ajax work ...
0
votes
0answers
13 views

How to use wp_get_attachment_image or wp_get_attachment_image_src instead of $instance['single_feature_image_uri']

I want to use wp_get_attachment_image() or wp_get_attachment_image_src(). But that widget is not belongs to any post type. widget() Image instance is single_feature_image_uri public function widget( $...
0
votes
1answer
9 views

Order by title Child Pages displayed in a Parent Page

I am using the code bellow to display a list of Child Pages on a Parent Page. I want to order the displayed list by Alphabetical order. How can I achieve this? function wpb_list_child_pages() { ...
0
votes
0answers
12 views

I want to add a custom select field in a WooCommerce Checkout - and based on the selection, open new text fields to be added

add_action('woocommerce_before_order_notes', 'wps_add_select_checkout_field'); function wps_add_select_checkout_field( $checkout ) { echo '<h3>'.__('Delegates').'</h3>'; ...
0
votes
1answer
31 views

str_replace with the_content is not working

I am trying to replace the a URL of the content with php. i tried the code mentioned below but it didn't work. is there any way to achieve this with php only? function replace_text_wps($text){ $...
0
votes
0answers
22 views

Reading URL Parameters

The following URL call, is redirected and processed by the 404.php page, indented to capture the s parameter. https://www.example.com/doc/?s=par For some reason, while try to processing the s ...
0
votes
0answers
11 views

Unable to hit hook with form submit build with “wp_ajax_{$action}”

I'm all I'm currently trying to build a hook using do_action( "wp_ajax_{$action}" ) on a Form submit. I built the following form. <div class="layout-gutter bg-grey-lightest p-4"...
0
votes
0answers
9 views

What do I add to specificy another category for a custom header? [closed]

This is current code, I'd like one more along the lines of elseif ( is_category('new-header-cat') || is_single() && in_category('new-header-cat') ) : <?php else: ?> <div class="...
0
votes
0answers
8 views

How do I create auto open and close alert push notification on WordPress site?

I am developing auto alert notifications on WordPress loop posts. I am looping posts using while loop and displaying on alert at time intervals. Now I don't know what do I do in order for me to loop ...
0
votes
0answers
15 views

Include User ID in iFrame URL

I seem to have hit a roadblock trying to figure out how to append the user ID to an embedded iFrame url address. I am using a third party app that tracks unique users (and invoices me accordingly). ...
0
votes
0answers
19 views

Getting an error when my plugin is updated, but the files update correctly

I have a plugin that I am using GitHub to manage my updates through the GitHub Releases feature. Since this is a private plugin I can't put in up in the Wordpress Plugin Directory. The plugin ...
1
vote
1answer
16 views

Add meta noindex to post if it has a specific taxonomy

How can I add the following line to the current post if the product_type = 'enviso_group_ticket'? <meta name=”robots” content=”noindex,nofollow”/> product_type is a default taxonomy of the ...
0
votes
1answer
10 views

How do I populate custom field with current user role in Woocommerce [closed]

I am trying to populate a custom field called Customer Type in checkout with the current user role. I tried the below in my functions.php of my child theme and thought it would work but it does ...
0
votes
0answers
8 views

Change Custom Post Type Permalink Structure [duplicate]

I want to change Custom Post Type Permalink slug order: From: example.com/cpt-slug/post-name To: example.com/post-name/cpt-slug Does this possible?
0
votes
0answers
25 views

Change the URL of an image from wp_get_attachment_image_src for Product Posts based on Category

I would like to change the URL of an image from wp_get_attachment_image_src for Product Posts based on their Category, for example: If a product post is in product category 1, this will be it's image ...
0
votes
1answer
9 views

Issue in displaying the ongoing event and current events in the post

I am developing a consultancy website which has event to it. I am using ACF for generating event Firstly the event consists of 3 things, Past Events Ongoing Events + current events + upcoming events ...
1
vote
1answer
21 views

Change the URL of an image from wp_get_attachment_image_src except in the frontpage

This is the code I used that is working, but I want it to work only on product posts and not on the frontpage. function alterImageSRC($image, $attachment_id, $size, $icon){ $image[0] = 'http://...
0
votes
0answers
12 views

Wordpress redirect from URL with BuddyPress

I am using the plugin BuddyPress on my WordPress site and when the user clicks on their profile they are redirected to the URL "/members/USERNAME/profile/home/". However, I do not want this ...
0
votes
0answers
8 views

I want to set multiple selected option( taxonomy terms ) values to database of a custom post type - taxonomy. It is only saving one value

My current php code is as below <?php //Select Paper Colour $paperColours = get_terms( array( 'taxonomy' => 'papercolour', 'order_by' => 'slug', 'hide_empty' => 0) ); ...
0
votes
1answer
26 views

How to create a custom config file and get data using inline JS in a wordpress page

I'm totally new in WordPress as well as in PHP and making my first application with it. Currently, I use 'HTML block Element' to add content with custom HTML and inline Javascript code on blank ...
0
votes
1answer
11 views

WPML best page selector with php

I have a multilingual website made with WPML. I have php code to run across pages but I cannot uniquely target the page with is_page(ID) since the ID of the page changes across language domain. I need ...
0
votes
1answer
15 views

A server-side hook failed when committing plugin code to SVN

We're trying to commit and push our initial release to the SVN repository assigned to us by the wordpress team. However when committing the code we're getting an error (probably because of the PHP8 ...
0
votes
1answer
36 views

How to disable send e-mail notification new comments for some posts

How to disable send e-mail notification new comments for some posts Sorry for my English
0
votes
1answer
34 views

Custom shortcode for displaying user based on a role parameter

I've created a plugin that with a shortcode displays all users with the custom role "ansatt". This works perfectly fine, but I'd like to be able to set the role as a parameter within the ...
0
votes
2answers
23 views

WP custom posts: filter results to custom taxonomy tag that corresponds to user meta field

I need some guidance on making a wordpress posts query responsive to user meta data, and whether it’s possible to do what I want within the query itself, or if further work is needed in the database ...
0
votes
0answers
19 views

Capturing variable after slash in domain

I'm developing an ecommerce website with Wordpress / Shopify API. I'd like to be able to capture discount codes through the URL. So if the discount code was code40, I'd like the enduser to be able to ...
0
votes
1answer
26 views

If is_page include/else not working all of a sudden

I've had the same code on my wordpress site for more than a year, and it's stopped working. This is part of page.php: <?php if (is_page( 83571 )) { include('adsense-schools.php'); } else { ...
0
votes
0answers
21 views

Update Images after edit via php

After editing images directly inside the upload folder via PHP-functions, I managed to automatically regenerate the meta data, the thumbnails and the WebP copies. (Checked via FTP! Even the displayed ...
0
votes
1answer
22 views

trying to put an active hover to my custom nav category buttons [closed]

I have a custom category buttons which each of buttons link and echoed the specific category at the same page. my goal is to put a active background hover color on the active link. here is my code so ...
0
votes
1answer
16 views

Search WordPress using static html page

So I have a .html page under my Wordpress website and I want to be able to use the search button on the static html page to search the search.php page, is that possible? Is this correct? This is ...
0
votes
0answers
14 views

Cant create table on plugin activation

I am trying to create table on plugin activation, I tried making the same function inside the class and calling it from the constructor, and I tried calling it outside the class and finally i tried to ...
0
votes
2answers
43 views

How to edit HTML of my website on WordPress? [closed]

There's a few parts of my website where I'd like to edit the HTML code. How to edit the HTML code of my website without the edits getting wiped out after an update? I've heard about child theme's but ...
1
vote
0answers
18 views

Embed html in php code

I am not following the PHP OOP as of yet. I have one main plugin.php file, which contains the main class of my plugin. This is where, I enqueue javascript file (plugin folder/assets/plugin.js) , which ...
0
votes
1answer
22 views

Variant Item SKU as Product Code

I am working on a new website for my company. We have products with variations. each variation have its own SKU number. When we select the product, the correct item is displayed in the cart with ...
0
votes
2answers
48 views

Use wp_head hook on template page

I try to use the hook wp_head on a template page but this does not work add_action('wp_head', 'to_head'); function to_head(){ //do stuff } I placed this code on a template part what is called by ...
0
votes
1answer
10 views

Redirect first comment (Thanks for comment) with show Autor name and beginning of the comment

Redirect first comment (Thanks for comment) with show Author name and beginning of the comment Sample: Open custom page (Why custom page? There will be some more information) with text comment Hi, ...
0
votes
0answers
18 views

Combine change Email Wordpress and woocommerce emails template

I use this plugin for customize woocommerce emails. But unfortunately I found out that it does not change the standard Core Wordpress emails. For example if client want change email in account details,...
0
votes
1answer
14 views

Run PHP 24hrs After Event Trigger

I'm a bit lost on this one and would appreciate some direction. I have created a plugin that sends a message to a user after they successfully sign up. However, I would like this message to be sent 24 ...
1
vote
2answers
33 views

add_meta_box (Will display only in specific page admin WordPress)

I am wondering how to add meta box in WordPress specific page admin, I mean when I create meta_box with code snippet below provided from source tutorial is really perfect and effective but one thing ...