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

How to check post meta isset or not empty during publish/save post?

How to check if a specific post meta isset/!emtpy during updating or publishing a post ( save_post() )?
user avatar
0 votes
0 answers
41 views

redirect after submiting post for review

I have a frontend page that allows "Tutor Instructor" role, to create a course and this course is a custom type post called courses, when the Tutor Instructor finishes creating the course he ...
user avatar
  • 5
0 votes
0 answers
25 views

Need to add a post’s featured image to a section on the frontpage

It looks like I will need to create custom PHP code for this and either add it to my includes directory within a custom PHP file, or to the functions.php file. I need the ability to use a featured ...
user avatar
0 votes
1 answer
28 views

How to redirect outgoing links via my own website

How can redirect outgoing links first to my own site? for example i got a recipe post and i got a outgoing link to another website this link is stored in a metafield $recipe_url = "https://...
user avatar
0 votes
1 answer
27 views

Wordpress Multisite login_redirect to primary blog and specific page based on role

I'm stumped trying to redirect my users to a specific page on their primary blog when they login to the root/main site on a MU setup. I have the site editors with a specific 'editor' role and then ...
user avatar
0 votes
1 answer
90 views

Finding the screen id of a page generated with add_menu_page

I'm at a basic level of WordPress + PHP and I'm trying to build a pretty simple plugin. I've set up the plugin correctly, and the plugin page is generated with function wpplugin_settings_page() { ...
user avatar
0 votes
0 answers
49 views

How to exclude labels from certain categories in a shortcode?

Good afternoon. There is a shortcode [alltags] that displays ALL site tags on a separate page of the site in alphabetical order with a letter. function wph_alltags_shortcode( $atts, $content ) { $...
user avatar
  • 1
0 votes
0 answers
11 views

Output product category link from WP_Query

I have a WP_Query that outputs products from given Product category name. For each product list I would also like to link to the category of that product, but I'm not sure how. My query: <?php $...
user avatar
0 votes
0 answers
23 views

How to implement __() function in my theme's php file?

I am translating a site with Polylang that was created by someone else using a custom theme. Some strings couldn't be found by Polylang, so I need to manually register them for Polylang to see. Now, ...
user avatar
1 vote
1 answer
72 views

Adding hreflang tags automatically in WordPress subdirectory multisite

We have a WordPress MU subdirectory network setup: www.example.com - main website, USA, global www.example.com/uk/ - to display for UK visitors www.example.com/au/ - to display for Australian ...
user avatar
  • 1,624
0 votes
0 answers
27 views

Pagination at category doesnt work with same name of page

i have a problem with my pagination but only at category page. I'am not developer, and i try fix it from few days. My pagination working if i make different name of pages for main BLOG, and category ...
user avatar
0 votes
0 answers
27 views

Hot to check if new posts have been published since page load and notify online users?

I want to show a div notifying online users that there are new posts since they have accessed the page, in the index and also if new posts have been added in the category or tag they are browsing. I ...
user avatar
0 votes
1 answer
26 views

How does add_option() function enable action hooks to fire right after actiavtion?

The documentation page says that the hook process performs an instant redirect after it fires. So, in order to do something right after the activation the page suggests using add_option like so, ...
user avatar
0 votes
0 answers
32 views

Unzip file in functions.php, and add it to cron

I have a file in the root folder of my wordpress installation (myfolder, wp-content, wp-config, and all other). I want unzip a test.zip archive in my myfolder folder in root directory. I try this ...
user avatar
2 votes
1 answer
36 views

Javascript code inside "<# #>" in core WordPress files .php

I found some interesting embeding JavaScript mix with HTML in WordPress php files, for instance: <?php // Template for the Attachment Details two columns layout. ?> <script type="text/...
user avatar
0 votes
0 answers
24 views

Nav Walker that shows only children and siblings of top level parent menu item

I have a nav menu that is structured like this.. Main Section 1 – Child Link 1 -- Grandchild Link 1 – Child Link 2 – Child Link 3 Main Section 2 – Child Link 1 – Child Link 2 – Child Link 3 Lets say ...
user avatar
  • 101
2 votes
1 answer
110 views

Find variables available at a given hook

I'm hoping for a simple way to tell/find/echo what the available arguments are available for use at a given hook. For example — function example_function($something){ //do stuff with $something ...
user avatar
  • 123
0 votes
0 answers
19 views

Change permalink structure specific category

I have a specific category that all posts that are in that category must follow the following structure: category-name/child-category-name(if any)/post-name The other posts will remain with the ...
user avatar
0 votes
1 answer
26 views

Adding onload to body for certain pages

I am looking for a function to add <body onload="prepareFrame('https://airtable embed URL here')"> to certain wordpress pages only. I know how to add a custom body class but not an ...
user avatar
  • 638
0 votes
0 answers
37 views

Add posts to custom table in database instead of wp_posts

What the code does: Imports posts, loops through all the posts and calls wp_insert_post to create a new posts for each import. Objective: Import posts and store them in another table, not under the ...
user avatar
  • 189
0 votes
1 answer
59 views

How to pass username in affiliate link in wordpress website

I need to pass current logged in user in wordpress website as SUBID in the affiliate link as follows. Affiliate link format is like below. https://affiliatenetwork.com/track?id=myuserid&url=https:/...
user avatar
0 votes
1 answer
48 views

how to get serialized post meta

I have posts that have video content and these videos stored in database like this (serialized) a:1:{s:9:"video_url";s:0:"";} This serialized data have post video urls but can ...
user avatar
0 votes
1 answer
17 views

How to remove the two duplicate values

How to remove the two duplicate values Example I have the variable 1 $help_brother: $help_brother = '30,45,12,13,14,15'; And the variable 2 Force World: $force_world = '45,12,15'; The result must be:...
user avatar
0 votes
1 answer
74 views

Hide Heading if ACF Field is empty

I am trying to add a "Local FAQ" section to all the individual location pages on a site with literally thousands of individual location pages. I am doing this by using ACF field in the ...
user avatar
0 votes
0 answers
51 views

Additional file upload in Gutenberg page options/featured image

I would like to add an additional image upload in the featured image part of the Gutenberg page options editor. e.g. as in the image below, but with an additional file upload area. In my PHP file I ...
user avatar
0 votes
0 answers
12 views

I want to include a particular word into the excerpt of every posts of a custom post type. How can I do that pragmatically?

I want to include a particular word into the excerpt of every posts of a custom post type. The custom post type "movie" has thousand of posts. It is not possible to manually edit the excerpt ...
user avatar
0 votes
0 answers
24 views

save_post trigerred twice

I am trying to add more functionality to the update button. My end result is that I wish to call a python script but for now I am messing around with writing a log file. This is resulting in the log ...
user avatar
  • 1
0 votes
1 answer
45 views

Scheduling an event inside plugin class is not working

wp_schedule_single_event is not firing. I wrote a function that is posting to external API, if it failed I schedule the same posting function to run 5 seconds later in cases of timeouts. Here's the ...
user avatar
  • 96
0 votes
0 answers
14 views

Disclaimer that will show every refresh of the page

Hello I have here a code that is based on a "where you first access the page you will see the Disclaimer template" but I want it to show every time I refresh the page <?php // ...
user avatar
  • 1
0 votes
0 answers
12 views

Change Dropdown jQuery to show/hide but with default place holder that shows all

How to set the jQuery so if default "Department" is selected show all, and only hide all else one other section made. for example, if non selected will be "Department", if "...
user avatar
  • 105
0 votes
1 answer
25 views

How to remove the message 'We could not find any results for your search' without changing template files and without adding posts/pages?

I take the question back with context. The goal is not to add posts or pages so that the post is replaced by the title of the post/page. The goal is not to modify the search.php file to remove this ...
user avatar
1 vote
1 answer
62 views

Escape when echoed

I've been trying to submit a plugin for review and I keep having problems with the echo line. The last version I sent was like this. <option value=""> <?php _e( '- Default', ...
user avatar
  • 17
0 votes
0 answers
179 views

Download file and redirect to page or vice versa

I have a Wordpress site with a custom post type called downloads. The post type has a file field added to it with Advanced Custom Fields (ACF). The downloads post type is used for download links ...
user avatar
  • 101
0 votes
1 answer
50 views

Programatically upload a file to be stored inside blob field in database, NOT on filesystem

old php developer here, very.. very new to WP, so be kind. As part of a plugin, I am trying to allow files to be uploaded with the intended destination storage in a specific table. I have the ...
user avatar
0 votes
1 answer
36 views

How to set a template with wp_insert_post

I'm trying to set my template to the Elementor Canvas when using wp_insert_post but it isn't working. It is creating the new page fine but not using the canvas. What am I doing wrong? { "action&...
user avatar
0 votes
0 answers
32 views

Password protect URLs

I have a Wordpress site set up with download links that either could be set as external URLs or links to media items uploaded to Wordpress. I would like to password protect these, so clicking a ...
user avatar
  • 101
0 votes
0 answers
98 views

Woocommerce. Get a list of products in the current category on the archive page and product page

I'm trying to create a small code that will display a list of discounted products that belong only to the category of products that the user is on, that is, if the user is on the clothing category ...
user avatar
0 votes
0 answers
150 views

AJAX function running TWICE with WordPress admin-ajax.php

I have a form submit event that calls a WordPress ajax function. The form submit event occurs only once (It is correct as expected). But the ajax function loaded TWICE (expected to occur once). Here ...
user avatar
  • 21
0 votes
2 answers
84 views

Wordpress Custom SQL Table with UserID Filter for results

UPDATE: I have realised that I need to use a plugin like PHP Snipping or Insert PHP to make this work, I have updated my screen shots to reflect where Im upto from my research. The code is working and ...
user avatar
  • 3
0 votes
0 answers
38 views

OOP PHP class extends TwentyTwenty_Customize in Child Theme

Not sure if OOP is covered here but i've copied the class-twentytwenty-customize.php file from the Twenty Twenty parent theme to my child theme and renamed it to class-customize.php because i need to ...
user avatar
0 votes
0 answers
21 views

Foreach loop is unexpectedly outputting an extra empty a tag

I am using a for each loop to output elements on a grid and I am using acf's gallery type to input images. It is outputting this extra a tag with empty space and no hrefs. See below Here is my php &...
user avatar
0 votes
1 answer
36 views

Automatically add images to a menu

I am calling a menu into a page, but I want to add images next to the title of the menu items. I have this code: <ol> <?php $navMenu = wp_get_nav_menu_items(2096); /*/Pass Nav Menu_id or ...
user avatar
  • 167
0 votes
1 answer
20 views

Add Block Before Entry Title Using PHP

I'm using this code to add a block before the entry title on the front page but its not working: $e = get_block( '552' ); $eblock = apply_filters( 'the_content', $e->post_content ); echo $...
user avatar
0 votes
0 answers
70 views

Time Delay a URL Redirect for Specific Page

I need to set a time delay redirect for a specific page. Reason is because we have a URL redirect on the specific page and it is not registering for a Google Analytic page visit conversion. So we need ...
user avatar
  • 63
0 votes
0 answers
21 views

How to add a custom filter (by coding) before access one wordpress page ? And where to call the custom filter?

My requirement is to create a survey in wordpress, and the user needs to log in before answering. But the login page uses our own business account, so we created a login page ourselves (using .net ...
user avatar
0 votes
0 answers
26 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
74 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
30 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