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
27 views

Delete images from media library when user deletes an image from ACF Gallery

When a user deletes an image from the gallery in wp-admin I need it to be deleted from the media library too. I have a function using the acf/update_value hook which works uncorrectly. When a user ...
user avatar
0 votes
1 answer
77 views

How to correctly escape an echo

In WordPress they recommend that I should escape any part of the code of my plugin that shows data to the user, I have made most of the corrections but this specific case I don't know how to escape ...
user avatar
  • 17
0 votes
2 answers
31 views

Custom PHP script throws critical error ONLY when editing page

I have the following script added to functions.php in my child theme: function getlatestfile() { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('wp-content/uploads/cams/'...
user avatar
0 votes
0 answers
19 views

PHP using external anonymous function inside class

I have two files. In file1.php I have an anonymous function: $myfunc = function($params) { // do something } in file2.php I have a class and inside this class I need to use the function ...
user avatar
  • 1
0 votes
0 answers
36 views

Array data not saving to specified sections. How to make seting independantly?

I think I am writing the array part wrong. When saving on this array if you set all five settings, the setting from the 5th option is saved on all the settings. But if you then set the first four ...
user avatar
0 votes
0 answers
13 views

How to make Subdomain work for product_tag?

I'm trying to find a way to make subdomains work for some of my product_tags. For example nike.myshop.com will display the content of myshop.com/product_tag/nike. I googled for a long time, but most ...
user avatar
  • 1
0 votes
0 answers
40 views

WP_REST_Response - How to return Gzip answer and add Content-encoding header?

This code runs correctly : function get_travelbooks($request) { global $tsp_mdlObj; $result = $tsp_mdlObj->read_travelbooks(); return new WP_REST_Response($result, 200); } Now I ...
user avatar
0 votes
0 answers
24 views

WP_Query - How to query all of post types categories

I added a custom taxonomy to woocommerce's products post type. The custom taxonomy is called Brands and is simply used to select the brand of the product. I am using wp_query to query all of the ...
user avatar
0 votes
0 answers
26 views

get_terms with specific id order

I have the specific query $queried_object = get_queried_object(); $taxonomy = $queried_object->taxonomy; $term_id = $queried_object->term_id; $isActive = 0; $postTerms = get_terms( [ 'taxonomy' =...
user avatar
  • 3
0 votes
0 answers
10 views

Customizer control save then return to default

Is it possible with default wordpress controls to use the radio control then save then automatically revert to default after each save. For example radio select 0, 1, 2 is option and you select 2, ...
user avatar
0 votes
0 answers
68 views

how to changes mobile menu toggle breakpoint in Wordpress

I want to change the mobile menu toggle breakpoint in twenty-twenty one theme, want to show on 767px but it shows on 481px by default.
user avatar
0 votes
1 answer
28 views

Dynamically switch file in get_template_directory_uri() | Function [closed]

I need to switch scheme color of my WordPress theme trough Redux option panel. My plan is switch the CSS file trough get_template_directory_uri() | Function. The scenario is: Create 2 scheme color: ...
user avatar
0 votes
0 answers
41 views

How to work Woocommerce pagination inside shortcode?

I have a shortcode that shows the orders history placed by user. It works, however I have pagination with WP_Query which is not working. When I click on any page number the same page is reloaded, the ...
user avatar
  • 101
0 votes
0 answers
5 views

Get page permalink in contact form

<?php function leverage_handle_ajax_request() { if ( ! empty( $_POST ) ) { require_once( plugin_dir_path( __FILE__ ) . 'recaptcha.php' ); if ( isset( $_POST['section'] ) &...
user avatar
0 votes
0 answers
15 views

Strange admin-ajax / CSS / $_SESSION issue

TLDR: I'm generating a random token on a front-end form and storing it in $_SESSION to later retrieve by the ajax script. THE ISSUE: The code retrieved by the ajax script does not match the one ...
user avatar
0 votes
1 answer
143 views

How to get woocommerce orders with get_posts method in a shortcode

I'm writing shortcode which must show all orders placed by current user. I followed this two guidee to get them: https://www.businessbloomer.com/woocommerce-easily-get-product-info-title-sku-desc-...
user avatar
  • 101
0 votes
0 answers
38 views

Create an user checklist system for a course plateform using ACF Pro and ACF Extended

I'm currently trying to develop a learning plateform on my website and I want to integrate a system allowing users to check a list of step defined for each course. I don't have heavy PHP skills to be ...
user avatar
0 votes
0 answers
10 views

Get quantity of children in all parents and add quanity to all UL class names

In wordpress php. Is there a way to get the quantity of children in all parents, all parent UL, and use the quantity count in title of all UL class names, so the output would be like this, see the UL ...
user avatar
0 votes
1 answer
38 views

Isn't Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}

I'm trying to count rows in sql table using SELECT COUNT(*) for the post view count. My code is function get_post_views($offset=0, $post_id){ global $wpdb; $get_visit_query = "...
user avatar
0 votes
1 answer
24 views

Show current custom taxonomy

I have a custom post and custom taxonomy my taxonomy is called "department" i have my loop showing my custom post, I am trying to also show all the departments (custom taxonomy) that my ...
user avatar
  • 105
0 votes
2 answers
40 views

Display Yoast meta-description `wpseo_desc` within loop of categories and fail silently if no data is set [closed]

I want to output the Yoast SEO category meta-description within a custom loop. Current code (below) works if there is a meta-description present. However, if no category meta-description is set it ...
user avatar
0 votes
1 answer
19 views

How to display already created menus via php?

So I have a couple of already created menus on my wordpress installation. What I am planning to do is display navigation menus in a sliding popup. I have tried using wp_nav_menu() but it always shows ...
user avatar
0 votes
1 answer
63 views

How to sort WooCommerce products page by latest in-stock items first?

How to sort the WooCommerce products page by latest in-stock items first and all the out-of-stock items to the last? Currently, I'm using a code snippet from "https://www.businessbloomer.com/...
user avatar
0 votes
1 answer
16 views

WordPress custom taxonomy not showing

I have a simple custom Taxonomy register_taxonomy( 'categories', array('career'), array( 'hierarchical' => true, 'label' => 'Departments', 'singular_label' => '...
user avatar
  • 105
0 votes
0 answers
18 views

Timber right sidebar in Wordpress theme

How can I add the right sidebar only in Blog posts using the Timber theme running in WordPress? I tried all I could find, but for some reason, it's not showing up correctly. Followed the docs. but I ...
user avatar
0 votes
0 answers
50 views

woocommerce remove coupon link does not work

Woocommerce remove coupon link does not work in custom cart page: Here is code my Code: <div class="report-text-cntr-cart row mr-0 ml-0 <?php echo ( WC()->customer->...
user avatar
  • 13
0 votes
1 answer
37 views

the_title() & the_content() are retrieving Post details inside a Page, after calling a shortcode

I'm trying to create a custom theme, since I need to convert html pages to be used at WordPress. In about.php page, I have this shortcode to retrieve posts of a category: <?php echo do_shortcode('[...
user avatar
0 votes
1 answer
20 views

Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)

I installed latest XAMPP & extracted latest WordPress to this path: C:\xampp\htdocs I activated default theme: Active: Twenty Twenty I created these: 1 Page called test: http://localhost:82/...
user avatar
0 votes
0 answers
17 views

Updating Metadata with Shortcode

I'm trying to create the below function to check a user's for the metadata field "order_review_cards", and swap the value for Yes-no or no-yes. Not sure why the code isn't working. I can do: ...
user avatar
0 votes
0 answers
14 views

Grabing default from cuztomizer php file instead of other php script

I've seen codes that use something like: $this->default; I don't know the logic for that style of code yet. To grab a default for spesific customizer control or from a configuration file instead of ...
user avatar
0 votes
0 answers
11 views

WooComerce Deposit: set specific shipping method and quantity based deposit amount

I am preparing an e-commerce (most specifically woocommerce) website, where customers will pay: either a certain amount of deposit money for each product upfront via PayPal and will pay the rest ...
user avatar
0 votes
0 answers
40 views

Create Columns with Custom Walker and CSS Classes

I want to create a menu in WordPress that using the CSS Classes (from Screen Options) you can separate the menu by columns and choose when to start and end the column. I have this information.. &...
user avatar
1 vote
1 answer
145 views

Make id column as AUTO INCREMENT on plugin activation

I am creating a wordpress plugin in which I am creating a table, the table is getting generated successfully on activating the plugin but the problem is, column id is not generating as AUTO INCREMENT ...
user avatar
0 votes
0 answers
23 views

How to store checkbox data for individual users?

I am working on a video-course website and I would like to add a checkbox next to each video so that when a student finishes watching the video, they can mark it complete and when they return they ...
user avatar
1 vote
2 answers
49 views

Scope for PHP Variables Assigned in functions.php or a plugin

I'm a web developer who works on WordPress sites and want to ensure I keep PHP variables out of the global scope. I have questions about this: If I created a $new_title = "test seo title"; ...
user avatar
0 votes
0 answers
33 views

WP_Query for woocommerce products with a pattern as a post_title

I am trying to make a wp query for woocommerce products. This will be implemented for a search bar, so the consumer can search for a desired product. My first go was this: $args = array( 'post_type'...
user avatar
0 votes
1 answer
17 views

Get access to variable from previous pageview, excluding ajax-calls

I want to generate a random string, and get it passed to the next pageview. I currently have the following code: add_action('init', 'set_global_pixelcapival'); function set_global_pixelcapival() { ...
user avatar
1 vote
0 answers
29 views

Populate dropdown with Child Pages based on Parent Page chosen

I'm trying to populate the Child Page dropdown with that of the selected Parent Page - If a specific Parent page is chosen it should fill the second dropdown with all Child pages listed under that ...
user avatar
  • 11
0 votes
0 answers
40 views

Cascading dropdown select search based on Parent Page & Child Page

How would I create a cascading dropdown select search where the first dropdown would host selected Parent Pages and the second to display the Child Pages of the selected Parent. When submit button is ...
user avatar
  • 11
0 votes
0 answers
15 views

Unset all main menu items except those with $menu_object->title == 'x'

Instead of listing all the menu items to remove. How to remove all main menu items except those with specific title? REMOVE ALL MENU ITEMS EXCEPT $menu_object->title == '#request-mockup#' if ( ($...
user avatar
0 votes
1 answer
46 views

What's wrong in my PHP code? I'm using Wordpress Astra Theme and I can't insert data into my SQL

<form method="post" action="functions.php"> <div class="form-group"> <input id="customer" name="Customer Name&...
user avatar
0 votes
0 answers
11 views

WordPress cascading dropdown selection search based on Parent Page & Child Page

How would I create a cascading dropdown select search where the first dropdown would host selected Parent Pages and the second to display the Child Pages of the selected Parent. When submit button is ...
user avatar
  • 11
0 votes
0 answers
24 views

Grabbing Image name From Product Image Gallery

When a user clicks the add-to-cart button I need the order to capture the image from the product-image-gallery that the user last clicked and NOT the default product image. Is this possible? Thanks in ...
user avatar
0 votes
0 answers
20 views

Counting number of posts in multiple (sub)categories using shortcode

I'm making a new cycling team website and on the home page i have 3 different type of stats: "Win, Podium and top-10" Now i want the number of the stat go up if i post something with for ...
user avatar
0 votes
0 answers
25 views

Display WordPress search results based on the selected Sub-Category

I'm trying to create a search using dropdowns in WordPress. I've got two dropdowns, 1 - Parent Category and 1 - Sub-category. The Sub-category will show automatically based on the selected Parent ...
user avatar
  • 11
0 votes
1 answer
58 views

Why is a wp function used in current PHP namespace's callback not resolved to global scope?

Imagine the following script: <?php namespace MySpace; class MyClass { public static function execute() { // Do something post_exists(1,'','','my_post_type'); } } ?> I'm now ...
user avatar
  • 359
0 votes
0 answers
12 views

Deleting records with AJAX, deleting records as I search

I have made a live search engine with ajax which can search for records form the database table, and now I want to include delete functionality in the output results. For this purpose, I have made one ...
user avatar
0 votes
1 answer
76 views

Updated to PHP 8.0 and Wordpress site not working

I opted out of extended PHP support from my hosting provider and unfortunately did not check to see if my Wordpress build would be compatible with PHP 8.0 (stupid, I know...I rushed because I didn't ...
user avatar
0 votes
1 answer
36 views

Checkbox show / hide output result

How can i fix a show / hide function in my plugin. The checkbox called "snup_check" at line 257 should be standard unchecked. If the checkbox is unchecked nothing should happens. If the ...
user avatar
  • 21
0 votes
0 answers
40 views

Wordpress database html table with pagination

I know how to display the WordPress database table with Foreach loop, but I want to add pagination to the output HTML table so that it should show only the first 100 results then I can use pagination ...
user avatar

1
3 4
5
6 7
202