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
1 answer
26 views

dynamic page using php from sql database

The Problem I am really struggling to get wordpress to generate a page dynamically based on the content of a database. The Context I have a sql database which contains unique slugs and Ids, and I am ...
user avatar
0 votes
1 answer
24 views

Execute PHP code only with specific user role

I have a WordPress website with woocommerce and I want to set a minimum order quantity for products. I have found code online which does exactly what I need it to do and it works perfectly.(the code ...
user avatar
0 votes
2 answers
27 views

Upload non-featured image to image field

I'm trying to upload some associated media to a custom post type. Using file_put_contents() I'm uploading an image and trying to set an ACF image field to be the path to that file. But reading the ...
user avatar
  • 126
1 vote
2 answers
328 views

Why does this code snippet create a critical error on my site? [closed]

This snippet used to work fine but with the update to PHP 8.0 it now breaks the site when a WC order is switched to this custom status //Add custom bulk action in dropdown add_filter( 'bulk_actions-...
user avatar
  • 113
0 votes
2 answers
40 views

Wordpress - Get Posts with Category data

i have a question about improving my solution. For my task i build a Gutenberg block which shows the latest 5 Posts. This Posts show also the Category Name in the Frontend part which have different ...
user avatar
  • 3
0 votes
2 answers
47 views

Usage of call back function of add_meta_box()

I am learning WordPress Plugin Development. My Code is like below. class Admin { public function __construct() { add_action( 'admin_menu', [$this,'news_meta_boxes'] ); ...
user avatar
  • 387
0 votes
0 answers
13 views

Repeat a function with 24hrs gap for n number of days

I have a function like this: $points = $this->get_fixed_points_to_earn(); that is fetching the value of get_fixed_points_to_earn. I have another function for this: $days = $this->...
user avatar
  • 31
0 votes
0 answers
30 views

WordPress redirects page query parameter in URL

I am trying to create pagination in my theme. Everything is ok except when I click on pagination buttons for example [example.com/blog/?page=2] it will redirect to example.com/blog, but it's ok for ...
user avatar
0 votes
0 answers
17 views

Woocommerce Custom Meta Boxes- How to only display if they actually have content

I've managed to add two custom meta fields to the backend of woocommerce, shipping and size guides, using the add_meta_boxes function, as I don't want to use the woocommerce custom fields section as ...
user avatar
0 votes
1 answer
29 views

no_rest_route error on custom routes

I'm trying to set up a custom endpoint. I've been following https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/ but I can't get the route to register. Below is my ...
user avatar
0 votes
0 answers
14 views

Change Language Title Pagination on Subdomain non Multisite

Please Help Me, Iam use WordPress non Multisite, but my website use multiple subdomain from category. All Subdomain use Language Default "Bahasa Indonesia", but i want change only title ...
user avatar
0 votes
0 answers
7 views

Make all scripts and styles be placed in <head> [duplicate]

I have approximately 25 scripts and styles, and wanted to know if it's possible to make a function that hooks into the wp_register_scripts and then apply the $in_footer to false on all assets. So far ...
user avatar
  • 101
0 votes
0 answers
20 views

Remove Custom Post Category In Wordpress Slug Using .Htaccess

I am battling for days now to remove a custom post slug from Wordpress permalink. My theme Category permalink looks like this: example.com/listing-category/category I want to get rid of the custom ...
user avatar
0 votes
1 answer
65 views

Warning: Attempt to read property "ID" on null in D:\xampp\htdocs\yba\wp-content\themes\young-brand-child\functions.php on line 162 [closed]

My website working without error in PHP 7 when I change PHP 8 the website is giving this warning. Warning: Attempt to read property "ID" on null in D:\xampp\htdocs\yba\wp-content\themes\...
user avatar
0 votes
1 answer
37 views

How to use the wpsnonce clone post link?

I have this link from a CPT, to clone a post, in this case post=30808: https://domain.com/wp-admin/admin.php?action=duplicate_post_clone&post=30808&_wpnonce=240f0078e7 Now, I need to use this ...
user avatar
0 votes
1 answer
18 views

pagination for custom post type archive page

I have a custom post type (gallery). On the archive page, I'm limiting the display to 12 items, with pagination links below. This works as it should, but I'm getting error notices: Notice: Undefined ...
user avatar
  • 3
0 votes
1 answer
36 views

Add a custom WooCommerce settings tab with sections

I'm trying to add a custom settings tab to the WooCommerce settings screen. Basically I want to achieve a similar thing to the Products settings tab, with the subsections/subtabs: I haven't been able ...
user avatar
  • 167
0 votes
0 answers
16 views

Hi need update in my terms for other taxonomy

I'm new to wordpress, and in this case I created 2 taxonomies, cat_notice and trash_notice, what I need to do is when I delete a term, instead of it being deleted, it is reinserted in another taxonomy ...
user avatar
2 votes
2 answers
46 views

How to show every second user different types of banners?

I have to create the next feature fore the project: We have two type of top-bar lines. We need to show every second user(or user session I think it's more easy) different types of banners. Okay I ...
user avatar
2 votes
3 answers
109 views

Validate and Sanitize WP REST API Request using WP JSON Schema?

I'm currently setting up my first WP REST API and am attempting to understand how WP implements JSON Schema for the API endpoints, and the docs are imho really poor and confusing; so I wanted to make ...
user avatar
  • 359
0 votes
1 answer
33 views

Building a REST API for your web app exposes primary keys of DB records?

I'm new to WP-REST and need to build a REST API for a wordpress project, but I'm somehow wondering about one aspect. Good practices say, and the built-in WP API for posts also shows, that you should ...
user avatar
  • 359
0 votes
0 answers
20 views

How to set all External Domain Links with nofollow Attribute from Header Footer Content and Excerpt using PHP?

I am trying to set all external links with nofollow attribute on all Wordpress site. I found so many site where code is available only for content and excerpt. But i want to set nofollow attribute on ...
user avatar
0 votes
0 answers
37 views

How to get post count of specific taxonomy that have store name & category

I am new in php and trying to learning php. I have taxonomy called dealstore. I have added one store name "Amazon" and two categories name "coupons and electronics". Now, I want to ...
user avatar
  • 1
0 votes
0 answers
8 views

Flatten Responses returned via WP REST API via WP_Error for obfuscation

According to this; I'm setting up the REST API of a website project. I'm returning the WP_Rest_Response for no matter which request in every possible end, with an according http status code, etc; no ...
user avatar
  • 359
0 votes
0 answers
12 views

Free search and custom taxonomy query not providing the same result

Two queries that should function the same, provide different results. I've created a custom post type called maarchey_shiur. I've created a custom taxonomy called maarchey_shiur_categories. If someone ...
user avatar
  • 96
0 votes
0 answers
27 views

Ajax call not working in wordpress through a plugin

I have 2 Ajax call the first is working but when it send the data to other the file send_data.php and when I try to run any wordpress function which is add_post_meta it doesn't work! This's the first ...
user avatar
  • 5
1 vote
0 answers
18 views

Is there a way to programmatically create multiple pages utilizing the same template but different content from a json file?

I have been tasked with creating geolocation pages that will all use the same exact template. The content writer is giving me all the "text" for the pages (which I am converting to json). I ...
user avatar
  • 11
0 votes
1 answer
20 views

Send Array from JS to php file then insert it in wp database through a plugin

This's my code it's success but when but I can't the return data from ajax in the same page. the mechanism is the user click the dropbox button and when he selects it returns dropbox_links and then ...
user avatar
  • 5
0 votes
0 answers
23 views

custom add note meta box with add button in wordpress

I'm making a custom note meta box for plugin, and I have a note box input and one 'add' button in the box with. The button saves the text but does not move the text to the notepad but instead stays in ...
user avatar
0 votes
0 answers
40 views

MySQL Query Returns Array () In Shortcode

This is in my theme's functions.php. I have an external MySQL database that I'm connecting to in WordPress with the following code, and I'm attempting to create a shortcode that shows the total of a ...
user avatar
0 votes
0 answers
15 views

Display Sibling WooCommerce Product Categories on Archive Page

To the lovely people of StackExchange, I've created the following code to list WooCommerce categories on category archive pages, and it's mostly working as I'd like. However, I'd like to modify it so ...
user avatar
0 votes
0 answers
15 views

Offer Download Links for Product Images

For a B2B shop, I would like to give customers the possibility to easily download product images. To do this, I would like to display links for the product-specific images directly on the product ...
user avatar
0 votes
1 answer
33 views

WordPress Settings API unable to save settings

So I can't seem to get the Settings API to save a field properly, I feel like I've followed ever single step, but I'm having no luck, so I wanted to reach out and see if someone might be able to spot ...
user avatar
  • 3
0 votes
0 answers
19 views

Checking page before applying image restrictions while uploading

so users can upload images on my website and I want to put some restrictions on these images while they are uploading. The catch is that these image restriction can only apply on one page, being the ...
user avatar
0 votes
0 answers
52 views

Wordpress Custom Add To Cart Button with AJAX

i made a custom add to cart button but i cant load it with ajax here is the code. i added this code into my functions.php // Add "Add To Cart" button // add_action('...
user avatar
  • 1
0 votes
0 answers
11 views

Custom reduce stock code affecting date_modified - How to bypass?

I have a stock reduction script that works perfectly. The only problem is, when a purchase is made and the stock is reduced, the date_modified meta is updated. This causes problems for other scripts I ...
user avatar
0 votes
1 answer
21 views

Wordpress get_media_embedded

test text <div class="video"> <?php $media = get_media_embedded_in_content( apply_filters( 'the_content', get_the_content() )); print_r($media); ...
user avatar
  • 1
0 votes
0 answers
7 views

Publish button now showing content after saving

I am working on a theme, which when I build a new header (which is a post) and hit publish, it hides/deletes all elements (looks like a css code that somehow, hides elements on the front). When I ...
user avatar
  • 13
0 votes
1 answer
19 views

Contact form - problem with displaying message about sent mail

I'm trying to develop a contact form for a language school website that runs on Wordpress. Disclaimer: I'm about 6 months into coding, so please forgive me for being new to this. I'm developing my own ...
user avatar
0 votes
0 answers
19 views

remove specificly the last <p> tag in all posts

How to remove the last line of content in all of my WordPress posts, which always have its own tag <p>...</p>? Ex: <p>content I want to keep</p> <p>line I want ...
user avatar
0 votes
0 answers
22 views

Problem with data collection in tables

I have the following to do. I am migrating web content from a joomla to a WordPress, and the problem that I present is that the joomla has a collection of data in tables that is not compatible with ...
user avatar
0 votes
1 answer
14 views

Having Issue on Redirecting With Session in WordPress

I am trying to create a simple login system in WordPress using core PHP but I am getting this error message Warning: Cannot modify header information - headers already sent by (output started at /www/...
user avatar
  • 193
1 vote
1 answer
17 views

Count the number of custom posts per user

I am using JetEngine, and the users can create CCTs (custom content types), that have a single post CPT I know already how to count the number of posts by the user, I am using shortcode for that ...
user avatar
0 votes
1 answer
26 views

User filter posts by year

I am looking to add a filter to a page so users can select the year and view only posts from that year. Something similar to the filter on this page: https://www.economist.com/weeklyedition/archive A ...
user avatar
  • 101
0 votes
1 answer
16 views

How to redirect non logged in mobile users to page on same site?

I have seen many like this question (like How to redirect non-logged in users to a specific page?) but none have worked. this is basically what I've come up with but it doesn't work all the time and ...
user avatar
0 votes
0 answers
23 views

can't unzip file

i'm created import and export function, The Export function download zip file to my computer The Import function when trys to extract zip file it's fails and can't open zip file. when i create the zip ...
user avatar
0 votes
0 answers
11 views

How to Redirect Buddypress Directories To Login Page For Non Logged in Users

How to Redirect Buddypress Directories To Login Page For Non Logged in Users? I'm also using the Yuzify plugin. It gives a code for it, but it's not working on multisite. Can anyone modify this code ...
user avatar
0 votes
0 answers
11 views

How to set value selected using select2 jquery plugin

In my file, i have small html bellow: <div class="dropdown-mul-2"> <select style="display:none;" name="dom767_options[all_posts][]" id="mul-2" ...
user avatar
0 votes
0 answers
16 views

Merge 2 product attribute terms

I have 2 similar product attributes and would like add the meta data(terms) to the other. So I would like to make a php function that : get list of all the terms from attribute 'reviewed_by' updates ...
user avatar
0 votes
0 answers
11 views

bp-custom.php is not working on a WordPress multisite environment. how to fix it?

I'm using the youzify plugin. It has an option: if you want to add a custom code, you need to create a file named bp-custom.php in the WordPress plugin root folder. And youzify provides some code on ...
user avatar