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

Uncaught Error: Call to undefined function get_user_by() after moving function from theme to plugin

I have a code I always used in my themes or child-themes. I'm doing right now a project with plugin-only as a solution, so I tried to copy paste some stuff from child-theme to plugin file, but I get ...
0
votes
0answers
17 views

Integrate otp in my custom singup form

so i have a custom signup page in wordpress who has 4 fileds , username , email , phone , password , i want when the user submit the form a popup or another page appear to ask him for the code that he ...
1
vote
1answer
57 views

Ajax call not working

I have the following wordpress snippet that is working fine except for the ajax call. I am receiving alert yes but not alert data. I suspect that the ajax url is incorrect but have no idea where to ...
0
votes
0answers
28 views

Add a "custom field" to a category that can be retrieved when viewing the category page with get_post_meta

I usually set a custom field customdata for posts and pages, that I can obtain when rendering a page with this PHP code: get_post_meta(get_the_ID(), 'customdata', true) Is there a way to set a custom ...
1
vote
0answers
16 views

Display menu point only if there are published posts in that category

I have a menu point called "Jobs". This is linked to a page that contains mostly posts of a specific category (Jobs). I would like this navigation point to be visible only if in the page ...
0
votes
0answers
25 views

Get only parent post in archive post

I created custom post type using cpt plugin and trying to create custom template to my new post type. I want to display only parent posts and then display child posts in parent post page, but when ...
0
votes
1answer
45 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
0answers
10 views

How to spell out a word in products/posts?

What would be the best course of action to create a text input box that pulls up products that are essentially letters to spell out a word in products? Where the products would have an attribute ...
0
votes
0answers
17 views

Replace old theme that understand old css (vcex_icon_box css_animation)

I have just updated a 4.9.3 old wordpress with the new 5.8.1. The theme, which was a custom one using WPBakery 5.1.1, is using old PHP functions (PHP has been updated also to the last version) so Im ...
0
votes
0answers
9 views

Change category thumbnail size

I have my whole page thumbnails set as 331x331px but somehow all category thumbnail showing 300x300px. Which makes the picture quality quite bad due to CDN automatic resizing. I tried all the settings ...
0
votes
0answers
13 views

How do I add a function to parent theme

I am looking for advice on how to add a function / hook to a parent theme. A colleague has installed a WordPress theme, but not child theme as I have tried adding a function to the child theme but ...
0
votes
1answer
15 views

Can't log in to WordPress wp-admin after adding code to functions.php

I am adding the following code to the end of my functions.php file to populate a taxonomy based on a Custom post's post-title. The problem is that when I add the code I get the following error trying ...
0
votes
0answers
21 views

How to change Elementor Template for Single Page Post on Load

I really need your help with the following issue. I have a custom Post Type Created. For this Post Type I have 2 elementor Single post templates: It appears like this: [elementor-template id="...
0
votes
0answers
9 views

Open_basedir errors - But setting basedir to none redults in 502 Bad Gateway

I'm getting open-basedir errors from various plugins, such as updraft plus and super cache. Changing open-basedir to "none" from PHP options resulted in a 502 error. I'm noticing that all ...
0
votes
1answer
35 views

Build A Custom SQL Query for WordPress Search

I was working on a code, where I used SQL to find something on my site. I realised that the SQL was giving me far accurate search results, and wanted to implement the same in my WordPress search query....
0
votes
0answers
22 views

Allow two posts (from different categories) to have the same slug

My permalink structure is /%category%/%postname%. How to allow two blog posts, of permalinks /categ1/myarticle and /categ2/myarticle to have the same slug myarticle? When I try to change the permalink,...
0
votes
1answer
20 views

Why would the child theme load in the Customize preview, but not on the site itself?

I have my child theme folder, the style.css sheet with the required template comment and some custom css, and I have the functions.php page with the required enqueing code. Everything seems to be in ...
0
votes
0answers
15 views

Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters

I have this line in functions.php: add_filter('post_link', function($link, $post) { return str_replace('foo-', 'foo/', $link); }, 10, 2); and now Wordpress successfully sees example.com/foo/bar as ...
0
votes
1answer
34 views

JSON REST API Wordpress only showing first 10 categories

Alphabetically ordered categories are shown first (first 10). If I try to show all categories in JSON / Wordpress, it's not showing it. So, imagine these are the categories: A B C D E F G H I J K (=10)...
0
votes
0answers
19 views

Get main parent category for post (WordPress/Advanced Custom Fields)

I am working with a custom category taxonomy field named ‘category-tax’ in WordPress using Advanced Custom Fields. I am trying to have the main parent category be a button for all parent and child ...
0
votes
0answers
18 views

Is it possible to order posts using multiple meta queries, i.e. show posts from first meta query, then the second?

I am using the following query to get past and upcoming events: $post_grid_args['meta_query'] = array( 'relation' => 'OR', // Get upcoming events array( 'key' => 'date', ...
1
vote
1answer
40 views

SQL QUERY - Select a value directly from the database

In my WordPress database, in the options table, there is a field in the option_name column which is called titb_flc_options, whose value is this: s:397:"a:10:{ s:16:"69c3d01e88aba503&...
0
votes
0answers
25 views

How to list datas from database in a topic?

I would like to list this datas Here: but I do not know how! Someone have a code example that can help me?
0
votes
0answers
18 views

Are there any drawbacks on opening a session_start in functions.php and header.php?

Are there any drawbacks on opening a session_start in functions.php and header.php? Especially from a speed / loading speed/time and resource perspective? Anybody? Happy to learn about this!
0
votes
0answers
11 views

Sending simple variable on single page to WP JSON

I like to send specific data from a post to my JSON response in Wordpress. I like to send the output of the variable "hatus" to the JSON response, but it does not seem to work. <?php ...
0
votes
0answers
22 views

How to run complex query using PHP

I have a rather long and complicated SQL query. I want to use commands like SET @varible, GROUP_CONCAT, PREPARE, EXECUTE, DEALLOCATE PREPARE, case when, etc. I need this data from the DB to construct ...
0
votes
0answers
84 views

Failed to load resource: the server responded with a status of 500 (Internal Server Error) through wp_admin_ajax.php

This is the screenshot this is the server error log generated [Sat Oct 23 19:39:50.880944 2021] [:error] [pid 14841:tid 47226270963456] [client 61.245.170.73:48465] [client 61.245.170.73] ModSecurity:...
0
votes
0answers
16 views

How to insert datas in the table on wordpress?

I created a plugin that have a button, when the user click in the button, my program should to put some informations inside the table, but my program just do not working, I do not why. My code: ...
0
votes
1answer
18 views

How to authorize viewing and clicking a function only logged users?

I am creating a plugin that allow the users logged to favorite the posts. At first, I create a shortcode for put in the posts. function add_favorite_shortcode() { global $post_id; $...
0
votes
0answers
35 views

Store ajax data in PHP variable

I made an ajax call to get ID from the dropdown menu, I want to get this data store in variable PHP to make something ajaxcalls.js $(".developer_select").on("change",function(...
0
votes
0answers
8 views

On saving Post My permalink is updated and category is removed automatically which cause the 404

Hi to all I am facing an issue with WordPress On saving my custom post My permalink is updated and the category is removed automatically from the url which cause the 404 for the post here is my ...
0
votes
0answers
15 views

What query string parameter is available for index.php, that works for both pages and blog articles?

I have a page /page1 and 2 articles /article1 and /another-article1. Which query string parameter for index.php is available to show the content? I tried: ?p= but index.php?p=page1 is working index....
0
votes
0answers
18 views

comment_post (if comment is approved OR $comment_approved === 1) not working?

I am working on a code through which I can send emails to the user when his/her comments get approved. then I get to know about comment_post. but it is not working. comment_post is working for the ...
0
votes
0answers
39 views

Get WooCommerce products with similar SKU

As a result of my research, I can bring similar sku ones no matter which product I enter, but I encountered a problem, the sku code of the product I entered changes. E.g: 1- ) 36.214.03 2- ) 36.214.19 ...
0
votes
1answer
34 views

How do I include SVG file used as featured image?

I'm new, can I use include() or get_template_part to load an SVG file uploaded as featured image directly in the HTML page? I need to animate the svg images, but i need to easily change the image on ...
0
votes
0answers
19 views

Create ACF Checkbox to get all ACF Values from Parent Page

I want to create a wordpress plugin which is be able to load the values of the parent pages ACF Fields into the Values of the subpages. Is there a way to do that? At the moment I have the code to get ...
0
votes
1answer
25 views

404 on old link after changing post url

Hello I have a problem where i have 404 on posts after changing url with php using this function wp_update_post( array( 'ID' => $post_id, 'post_name' => $...
0
votes
1answer
326 views

PHP Warning: Attempt to read property "term_id" on bool

Since updating from PHP 7.4 to PHP 8, my error_log is now full of lines like this from a child theme I'm using: [17-Oct-2021 13:30:38 UTC] PHP Warning: Attempt to read property "term_id" ...
0
votes
1answer
28 views

Use value from Ajax call in PHP function

I have a ajax script that will take a value from a select from on onchange. This works well, and with console.log I can see the correct value. My select form triggers a reload, and I see the value in ...
0
votes
2answers
95 views

How a HTML form can trigger a PHP function?

I'm new to the Wordpress/PHP world. I want my page be able to communicate with an API that I build myself. So for this I have a form on my Wordpress Page using a HTML code widget which looks like this:...
0
votes
0answers
12 views

update custom taxonomy custom fields

I have a function that runs when when i click save on custom post type posts. It gets some values from the post and i want to update the custom field of the post's custom taxonomy add_action( '...
0
votes
0answers
15 views

Prepend to all image URLs with PHP, only for mobile devices

Is there a way, with PHP, to prepend my CDN service's URL to all of my images only when using a mobile device? The reason I ask to do it with PHP is because my site is AMP compatible, which doesn't ...
0
votes
2answers
30 views

require_once() if a product in woocommerce contains a tag [closed]

I try to require_once() a file, if the condition of a specific tag is met, on a woocommerce single product page. I've added following to my functions.php if(has_term('xyz', 'product_tag')){ ...
0
votes
1answer
15 views

How exclude or skip post type with get_next_post_link

I have a post type called families where I add personal information of each family, inside the data there is an option called status. *IMPORTANT: The fields are created with ACF CUSTOM FIELDS These ...
0
votes
1answer
33 views

the_posts_pagination() not working in wpquery

I'm trying to create pagination to the custom wp_query here is my code: <?php $btpgid=get_queried_object_id(); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = ...
0
votes
1answer
15 views

Automatic excerpt is not shown with the_excerpt() command

I've been looking for an answer to this question for a long time, but haven't found anything: how come when I use the_excerpt() on a given site it doesn't automatically print the first few characters ...
0
votes
1answer
32 views

Settings API form - submit with AJAX

I'm creating a plugin where I have a dashboard that is done with Settings API. I'm trying to save data from that form via AJAX. Form: public function agy_dashboard_page() { ?> <form id=&...
0
votes
1answer
19 views

Custom Login page, redirection and restrictions

I'm having some issues with my custom login page with redirections and restrictions. Any user can browse a 'community' page but they can't access the 'distributors' pages. I have set a rule so if ...
0
votes
0answers
13 views

How to remove Login from in my account page

I have created sperate login / register form in my website.. But when a user click on my account they are getting login form.. So how can I remove it ? I already have done some basic woocommerce ...
0
votes
0answers
15 views

Filter taxonomy by CPT

I have the following code that shows all the categories within the "category" taxonomy, it works perfectly but I need to filter so that it shows only the categories of a certain type of CPT ...