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.
10,557
questions
0
votes
2
answers
1k
views
Using PHP Code Snippets to query a database, $dbconnection->get_results is outputting nothing
I'm currently trying to run this php code snippet in a WordPress Page using a PHP code snippet extension.
//Database connection script
//Connecting to our master database
global $wpdb;
$hostname = &...
0
votes
0
answers
9
views
Add Imports to Existing WordPress Import Map
How can imports be added to the existing WordPress import map?
Preparing the Module
I have a JavaScript module threeDTest.js which is enqueued using a PHP short-code (set to run everywhere):
...
0
votes
1
answer
878
views
How to disable PHP functions in Wordpress?
I have a Wordpress site running on my local network. I want to disable dangerous functions like system and exec as a safety precaution. This site is run with a simple PHP server instead of apache2 or ...
0
votes
1
answer
966
views
offset and max_num_pages in pagination gallery
I rewrote the code galleries and stopped at the pagination. How can I get the maximum number of pages? at the moment I can not define it, and put a test for the number 5.
(Here "for ($ i = 1; $ i &...
0
votes
2
answers
927
views
Run code before Wordpress loads and insert data into WP if need be
I've done my requisite research and can't seem to find an ELEGANT way to do this.
We have a Wordpress app with some fairly intensive session management requirements and now need to run some old code ...
0
votes
2
answers
1k
views
How do I display PHP file contents on front end of Wordpress?
I am working with a third party API for events, the results of the GET request I've written are rendered/displayed at this URL (inside the SDK folder):
https://example.com/skiddle-php-sdk-master/demo/...
3
votes
1
answer
912
views
Image upload via FTP to wordpress media library
Is there any permanant way to upload images via FTP to WordPress media library other than the available plugins which don't really work well most of the time? I would really appreciate if anyone ...
1
vote
1
answer
1k
views
PHP FATAL ERROR [closed]
My website has a PHP Fatal error: Array and string offset access syntax with curly braces is no longer supported in /var/www/vhosts/katalytes.com/httpdocs/wp-includes/script-loader.php on line 706
...
0
votes
1
answer
21
views
Custom page template from plugin does not work with pre-installed themes in WordPress 6.6.1
So I have a simple Wordpress plugin that just allows me to use custom page templates. Here's the code:
my-special-template.php
<?php
/**
* Plugin Name: My Special Template
* Description: Awesome ...
1
vote
1
answer
767
views
Hide author from search results meta, still display date and categories
How can I hide just the author from the post meta in search results, while keeping the date and categories?
I know I can use something like:
.post-meta .author { display: none; }
to hide the author ...
1
vote
2
answers
779
views
How to pass aa JS variable to PHP?
I am fetching data from an API using JS. How can I use this data with PHP. More specifically, assign this data to a $_SESSION variable in PHP so that I can use it in other pages(templates files)?
0
votes
2
answers
2k
views
Show last 5 posts from specific category
I'm trying to show the last 5 posts from a specific category, which will be linked to a function so i can insert the shortcode in a Wordpress page. The code i have is as below, it does everything i ...
1
vote
1
answer
812
views
Add a CSS class based on categroy id to archive pages
How can I add a css class based on categroy id in archive pages body in wordpress?
I want to style each category page different
1
vote
3
answers
1k
views
Import Instagram post as Wordpress post
I've been searching a lot but haven't found one very simple thing: how to import a post created on Instagram and turn it into a Wordpress post, that is, copy one Instagram post (text + photo) and ...
0
votes
2
answers
1k
views
Defining constant in a plugin to use in another plugin
I am wondering if this is possible or if there is another, better way, of doing things. Google-foo didn't help.
So, I have two plugins, aa-frontend and aa-site. I need to define a constant or ...
0
votes
1
answer
1k
views
Multiple Tag Filtering
I am writing a theme for Wordpress and I need a tag filter tool for posts, that can filter by multiple tags simultaneously, without a submit button, no checkboxes, no radio’s, and a show all posts ...
0
votes
0
answers
11
views
Custom Dynamic Tag in Elementor not showing image
Hi I am trying to add dynamic tags to the wordpress "image" widget, so that I will be able to choose custom featured image: second-featured-image and third-featured-image.
These second and ...
0
votes
1
answer
798
views
Run do_shortcode on php template using JS function
I want to run a shortcode using the [jobs] on my PHP template. I'm using the WP Job Manager plugin. A sample code:
<?php
global $post;
$company_name = esc_attr(urldecode(get_query_var(...
3
votes
1
answer
1k
views
Wordpress can't find temporary folder, but folder it's looking at has correct permissions
So, I've spent a couple of hours looking around the internet to try to figure out this problem, since it seems like a dumb one that would probably be a duplicate, but apparently it isn't.
I'm hosting ...
0
votes
1
answer
2k
views
Update user_email via php - WP 4.7
I am brand new to php and web development. I've made a front-end edit profile page for users, and every field updates except email (but, everything else is user meta). I have spent way too long on ...
1
vote
1
answer
125
views
Create a custom plugin with dynamic child pages listing database records
I am developing a simple lean and mean custom plugin which has the purpose to list records from some database tables. Goal is to list data via url /teams/{category}/{id}.
I've created a basic plugin ...
0
votes
1
answer
830
views
How do I change tab url
I'm currently editing an affiliate plugin. I have added the affiliate plugin as a tab in 'My account' as well as using the plugin's shortcode to display the content there. Although when I click on the ...
0
votes
2
answers
36
views
Split titles by the " - " in Wordpress
I wanted to divide a Wordpress post title by the hyphen, in PHP and HTML in a Wordpress page for different div's.
Here's an example of the title i wanna divide "Charli XCX ft. Billie Eilish - ...
0
votes
2
answers
1k
views
How to save the output of php variables used in inline css code to the main style.css?
I have some PHP variables that each represent some user settings set via a theme options interface such as:
theme colors
typography
etc.
All these variables are in a file called dynamic-style.php:
&...
0
votes
1
answer
872
views
Using Tag Groups: Displaying groups and adjacent tags of current post
I am trying to use tag groups (plugin) and tags as a way to display basic info on a portfolio/blog website's posts. I have organised them as *ex. Tag Group: Year / Tags: 2012, 2013, 2014... etc and ...
1
vote
1
answer
935
views
WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
Desired outcome
I want display: none to be applied to the entire table after form submit button is clicked,
because once I got the order number ( $order->get_id() ), in a second step I want to ...
0
votes
2
answers
2k
views
Open image gallery on link click
I have a very simple wordpress problem, but I'm still struggling to figure out the solution. I have an anchor tag, and I want it to open an image gallery in a lightbox (as the default behavior when ...
0
votes
2
answers
745
views
Open all external links in new window - need help with the code
I'm using this code to open all external links in new window (site is based on Wordpress):
/* OPEN ALL OUTBOUND LINKS IN NEW TAB */
function autoblank($text) {
$return = str_replace('href=', 'target="...
1
vote
1
answer
897
views
Integrating PHP into Javascript to display map markers with Google API - problem with wp_localize
I would display Google maps markers on custom site temple with Google API maps. I do everything like this post: Integrating PHP into Javascript to display map markers with Google API
But a console ...
0
votes
1
answer
908
views
jquery & ajax getting data from php in wordpress . admin-ajax.php returns 400
I am working on an arbor.js graph. What I want is to send member id query it from php return member tree json to again to jquery script. then print the tree.
here is HTML form
<form action="&...
0
votes
1
answer
1k
views
Custom shortcode being shown in WPBakery backend rather than the block
I have a nested element called Hero Slider. Hero slider is the container and it can only contain a Slider item.
However, my shortcode is being shown in the WPBakery backend maybe suggesting a syntax ...
0
votes
2
answers
815
views
Custom PHP form needs refresh to load page correctly
I have a single page site with all content on it. The only other page I have is a "thanks for submitting the contact form" page. In this "thankssubmit.php" page I have my PHP form ...
0
votes
1
answer
919
views
How to use phpspreadsheet reader with $wpdb
I am trying to import an excel file on a webpage with a submit button. As far as I can tell, the only way to do so is to use PhpSpreadsheet. How can one incorporate PhpSpreadsheet with $wpdb and ...
1
vote
1
answer
1k
views
How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
Sorry guys, had to post this again as site wouldn't let me respond to comments (new account).
I have been working on some code to decrease quantity of a variable product based on the numeric values ...
0
votes
2
answers
1k
views
Override 404 when navigating to single php file
I uploaded a php file in the root directory of my Wordpress site that I need to be able to access directly through the browser.
When I do, it looks like Wordpress takes over, triggers a 404, and ...
0
votes
0
answers
321
views
Is it secure to use SMTP password in .php file in WordPress website?
Currently I am making feedback contact form without a plugin. Trying not to use plugins if possible. In action .php file there must be written server settings such as SMTP server, SMTP username etc. ...
0
votes
1
answer
1k
views
wordpress ajax pagination
I'm working on a WordPress Theme (create a custom theme) and using AJAX as pagination for my Custom Posts.
So I'm going to load pages with AJAX but the problem is when I click for next page, instead ...
0
votes
1
answer
762
views
Using ACF Relationship field to set post type to draft or published status
I am currently using the ACF Relationship field selector to query through a custom post type for locations to show various pages. These pages are "service" pages that can be shown or hidden ...
1
vote
2
answers
5k
views
WP Fatal error: Call to undefined function get_template_directory_uri()
theme:
functions.php
function one_admin_menu() {
add_menu_page(
'One Dashboard',
'One',
'manage_options',
'one_menu',
'one_menu_url',
'dashicons-...
0
votes
1
answer
735
views
How limit the width of a fixed menu-bar on scroll?
my primary menu-bar has transparent background. To have the menu visible always on top I looked for a solution and got the 2 codes you see below.
This code works fine, except the width of the menu-bar....
0
votes
2
answers
1k
views
How best to check if a user is from China and hide content?
To speed up my website in China I thought of hiding blocked services from Chinese users and wrote this and put it in functions.php
$isInChina = false;
$ip = $_SERVER['REMOTE_ADDR']; // This will ...
0
votes
1
answer
1k
views
Non-static method error when trying to use class in widgets
I'm trying to call a method into a function widget. The $this of the widget is passed to that method, but I get the following error:
Strict Standards: Non-static method class_name::method_name() ...
0
votes
2
answers
2k
views
Need to forward Data from WooCommerce Webhook sent to same site Wordpress REST API custom endpoint
I created a Wordpress REST API custom endpoint to be used as a Webhook URL in WooCommerce in order to convert the received data and then send it to a third party system, but the endpoint apparently is ...
1
vote
2
answers
54
views
Warning: Undefined variable $post_id
Hi can anyone please help.
I'm no computer buff and need a step-by-step guide if possible.
In getting this error on my product pages:
Warning: Undefined variable $post_id in /customers/5/f/d/...
0
votes
1
answer
1k
views
Polylang and template files
I divided the website i am making in diferent template files for example:
Category for blog -> category-blog.php
Category for projects -> category-projects.php
But now I am using the POLYLANG ...
1
vote
1
answer
753
views
split 1 cart item into instock and back ordered
If I have a stock count of 2 and I allow backorders and a client adds a quantity of 5 to the cart, the cart shows 1 line item with a quantity of 5 on backorder.
Is there a way to split this cart ...
0
votes
1
answer
2k
views
index.php file keeps redirecting to a non-existent index.html file?
Every time I try and visit the index.php file on my website, it automatically redirects me to an index.html page. I have no redirects in .htaccess. My wordpress site is in a subdomain, but it ...
0
votes
1
answer
805
views
url not using query string no longer working
I have a few websites where I have coded a custom feature to get data from the database, these are all older sites. the page fetches info by grabbing the last part of the url and turning it into the ...
1
vote
1
answer
1k
views
Wordpress child pages not working
I am creating a wordpress CMS and I have added multiple pages under one parent page. I am generating the links for all the child pages of a page and then when user clicks on the links, they should be ...
0
votes
3
answers
1k
views
How php content after the first and second paragraph
You have used the code of this question (Show content after the first and second paragraph) and it works correctly for me.
<?php
$paragraphAfter[1] = '<div>AFTER FIRST</div>'; //...