Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
27 views

Site broken by unedited php?

I have a wordpress website hosted in Plesk. I last looked at it a couple of weeks ago and all was well. I tried to go in yesterday and Plesk is telling me the wordpress installation is corrupt. It ...
0
votes
0answers
15 views

Taxonomy Child Term, Counter is staying on 0

I'm stuck on the counter for the child term. See Image: What did i try? Make use of: wp_defer_term_counting(true); wp_update_term_count(); Both of this functions didn't work inside my code. ...
0
votes
2answers
20 views

How to pass argument to add_action while the method is inside a class?

in my functions.php I have require 'autoloader.php'; add_action('init', 'MyClass::make'); and in my MyClass class I have class MyClass { public static function make($type) { var_dump($...
1
vote
1answer
13 views

How to Use Parameters with a Do_Action Function Within PHP Tags

I'm using a WordPress plugin that allows integration actions to integrate it within a theme. Using GeneratePress' Elements feature, I'm adding the action as a hook. Currently the code I'm using is: &...
0
votes
0answers
25 views

current-post-parent for custom post type

I have 2 archive pages on my site. First "News" is for standard wordpress posts. Second "Projects" is for my custom post type. When I go to specific post from "News" archive then my menu position "...
1
vote
2answers
109 views

How to limit the content coming from wordpress shortcodes?

I am working on a wordpress shortcodes in which I want to the limit the content coming from a xml. The code which I have used for wordpress shortcodes is: function podcast_func( $content = null ){ ...
1
vote
1answer
69 views

“before delete post” action fire when the post is updated?

I'm trying to create notifications only when I deleted published posts, but it fire when I update any published post? What I'm doing wrong! Thanks. function deleted_published_post_notify_author( $...
3
votes
2answers
125 views

Display a text message if the shortcode is not found?

I'm using the do_shortcode function to add a shortcode in a page. But I would like to check if that shortcode exists before displaying it. If the user has no gallery, I would like to display a message ...
0
votes
1answer
20 views

I am trying to make a field show and save from quickedit screen

I have a select box with some options. It appears in the normal product edit screen with the following code. function we_skroutzxml_custom_availability() { woocommerce_wp_select( array( ...
0
votes
1answer
16 views

PHP warning with code for nav menu walker

[UTC] PHP Warning:  Declaration of description_walker::start_el(&$output, $item, $depth, $args) should be compatible with Walker_Nav_Menu::start_el(&$output, $item, $depth = 0, $args = ...
0
votes
1answer
40 views

Add element after navigation element title don't works like I expect

I'm currently trying to add an empty <span> after every item title in my navigation which has childs. So only dropdown elements. Sadly also some of my non-dropdown items getting a <span> ...
0
votes
1answer
23 views

How can I count ACF sub_field with a certain value

I have a sub field that have several different values. What I'm trying to do is count the number of rows if they're equal to Mayor. So my code looks like this: if( have_rows('candidates') ): ...
2
votes
2answers
108 views

Using a function written in my functions.php file within the header.php file

I have been asked to do some work on a site where the old developer has written this function (create a variable that stores the users avatar into an img tag) into the functions.php: add_filter('...
1
vote
1answer
43 views

Woocommerce get selected shipping zone id for the current user

How can I get the selected shipping zone id based on current user in WooCommerce? I tried the code below, but I didn't get the zone id from the cart page: $bh_packages = $cart->...
0
votes
0answers
35 views

I want to view PDF files in attachment page (attachment.php)

I want to view PDF files in attachment page (attachment.php) When uploading a PDF file it is not reviewed but appears as a link to download
-1
votes
1answer
16 views

Generating a number based on post ID

I am trying to generate a number that will be 5 digits including the post ID. For example: if post ID is 25, the number will be 00025. So far my codes are below. It's working but is there any better ...
2
votes
1answer
18 views

Generate an array of parent/child page IDs, based on parent page name

I've been using the following functions (updating IDs manually) to group parent & child pages into an array, which I then use in an if/else statement to present content depending on whether or not ...
1
vote
0answers
19 views

send_headers don't work on wordpress multisite

I have written a simple plugin to send some security http headers. I've tested it on various wordpress installations but on a wordpress multisite network it seems that the headers are not sended. The ...
0
votes
0answers
22 views

How to check from which page the user is coming to the current page?

Is there a way of doing this with WordPress aside from using $_SERVER['HTTP_REFERER']? Maybe something like a blend of $_SERVER['HTTP_REFERER'] and is_category(). Something like, came_from_category( ...
0
votes
1answer
19 views

How to create an Email Subscription input in WordPress?

I can't find a good guide to create a simple input, that allows the user to submit his email and add it to a user's email's database in WordPress and also auto send the user a confirm email. I'm ...
1
vote
1answer
39 views

Write to / remove from default .htaccess file from plugin?

I'm working on a WordPress plugin, and I have a checkbox option to add cache control headers. I'd like to write to the htaccess file if the option is set to 1, else remove the new content. I've been ...
1
vote
2answers
44 views

How can I add a custom class to only nav sub-menu > li > a items in WordPress?

I've this DOM here: <ul class="sub-menu"> <li id="menu-item-1424" class="menu-item menu-item-type-taxonomy menu-item-object-product_cat"> <a href="#">Item</a> &...
1
vote
1answer
23 views

Add keywords meta to index.php page

I've created a php script to add keywords to my posts and pages. My question is about the wordpress index page. Is there a way to add the <meta name="keywords"> tag also to the home of my ...
0
votes
1answer
24 views

Advice on creating a WP Archive Template with Custom Taxonomy (get_term_meta)

I have created some custom taxonomies (using WordPress Pods) and they work great - but there's just one thing that I need them to do, and here's my question: How do I go about creating an archive ...
0
votes
0answers
13 views

Pagination not working — custom theme code

I am a "null" when it comes to PHP and I need help fixing this code. Don't have support for the theme anymore. Page affected: truustudio dot com/journal if ( ! function_exists( 'lobo_pagination' ) ) {...
1
vote
0answers
13 views

Why ajax doesn't work on certain wordpress hooks and reload the page instead?

I built an ajax function which works perfectly when i hook it to admin_head or admin_notices hooks but it doesn't work when i hook it to manage_posts_extra_tablenav hook, instead of doing the ajax ...
0
votes
1answer
21 views

Site title not showing. Please help me

Please help me, My WordPress site's title not showing. It's just displaying the domain like, www.example.com. site: https://happyygarden.com Please check my site code and suggest how to display the ...
0
votes
0answers
15 views

How to track and restrict external download script by logged in wp users?

My goal is to restrict direct download of external url (which has script) only to wordpress logged in users. I think we should track it by wordpress logged in user cookies. But i need a way to ...
1
vote
0answers
16 views

Why ajax doesn't work on certain wordpress hooks?

I built an ajax function which works perfectly when i hook it to admin_head or admin_notices hooks but it doesn't work when i hook it to manage_posts_extra_tablenav hook, instead of doing the ajax ...
0
votes
1answer
26 views

wp_mail function ends up in spam?

I created a wp_mail function which I use to send an email when a specific button is pressed. This works great, except that it will always end up in the spam instead of the inbox. This is the function:...
0
votes
0answers
22 views

autocomplete in wordpress using ajax with json-data

The scenario is whenever client press the key, automatically the suggestion should come below the text box, and that suggested value is fetched from the database. Here i am stucked in a situation ...
0
votes
1answer
24 views

woocommerce subscriptions - get expiration date

Using the call back hook, I can get the subscription information of everything EXCEPT the expiration date. Any thoughts on how to grab this. This is what I have: function ...
0
votes
1answer
27 views

add_filter() inside another add_filter()

I'm simply trying to call one (update post description) if the other signals out of stock. They both work perfectly independently: function single_product_short_description( $post_excerpt ){ ...
0
votes
0answers
18 views

how to insert/ import wp custom post type data manually into database

I have created a custom post type with a few custom fields in WordPress. I need to insert this custom post type data manually insert/ import into database table from my another table. My custom post ...
0
votes
1answer
49 views

How to create pagination for users list using custom array?

After searching I didn't found any solution, So I'm wondering how can I create pagination for users list like that? I'm highly appreciated your help, Thanks. <?php global $wp_query; $...
0
votes
1answer
28 views

Send Notification after post published was working but stopped after the last WP update

I'm just wondering why this snippet stopped working! It was working before the last WordPress Update! I'm using DW Notifications plugin and work without any problem in another functions. There are ...
0
votes
0answers
11 views

Change the product page 3rd party API

I´m trying to change product page inside a plugin that I´m developing but I have no idea what I´m doing wrong? I have tried to make a new curl request but from what I herd curl is not a thing in WP. ...
0
votes
2answers
49 views

Way to bulk make all my tags lowercase?

Is there a way in mySQL or otherwise to bulk convert all my tags into lowercase? Thanks!
0
votes
0answers
40 views

Using previous_post_link next_post_link but with a filter on a custom field

I have a wordpress site in which I have setup a custom field show_post of type True / False. Lets me control showing of posts of course. But I can't figure out in php when using previous_post_link ...
0
votes
1answer
34 views

Wordpress yoast seo plugin - parse snippet var in meta description

I am using this function to get the yoast meta description $metadesc = get_post_meta( $id, '_yoast_wpseo_metadesc', true ); But it is returning the snippet variable. From transitional styles %%...
0
votes
1answer
26 views

Get user by meta data key and velue

I have create custom user meta, but it was array how i can call only one of them by key like I want to get only course_id = 22 list. Here this my user meta array [certifications] => Array ...
0
votes
0answers
16 views

Permalink like example.com/taxonomy/post_type/postname

I would like permalink structures like this: example.com/%post_tag%/post_type/postname for posts example.com/%post_tag%/post_type for archive page of post_tag filtered with custom post type archive ...
0
votes
0answers
36 views

How to filter specific element of an array in wordpress/php?

I have a php code as shown below in which I have added Line#A for the debugging purpose. <div class="vidlist-main__meta cf"> <?php //if ( has_excerpt() ) {the_excerpt();} $tags =...
0
votes
1answer
14 views

How to apply 'add two more posts' to media content?

Goal: on media pages (image), locate the original post the images were added to (Wordpress already does this) and then print the two previous articles. This code prints the two previous articles ...
0
votes
1answer
36 views

Generate and send ICS file through WordPress

I'm writing a custom plugin for reservations. I need to generate an .ics file that needs to be sent to a predefined email address. I've tried some library like ZContent iCalendar and a PHP script ...
0
votes
1answer
27 views

Add to previous posts under post

Goal: After each post (that contains under a certain amount of words), display the two posts that were published before it in that category/tab. I found this on stack, where they do something ...
0
votes
1answer
25 views

Trying to publish a little bit of Javascript on the homepage AND at the bottom

<script type="text/javascript"> function toggleDiv() { var triggeredDiv = document.querySelector('.triggeredDiv'); if (document.getElementById('myonoffswitch').checked) { ...
0
votes
1answer
37 views

Custom Yoast Breadcrumbs URL

I'm trying to change the link in the default Yoast SEO Breadcrumbs. The current Breadcrumb is Home / Projects / My Pretty Project And I want to change the "Projects", and it's link, to "Case ...
0
votes
0answers
22 views

How to disable sub menu items from being created?

In WordPress under Appearance > Menus there is the visual menu builder where you can "indent" items to make them sub items of another menu item. I would like to disable the ability to make items sub ...
0
votes
1answer
36 views

URL rewrite rule

I have taxonomy product_brand and product_cat I have a link: /product_brand/brand_name/?attributes[product_cat]=product_cat_id How to convert to pretty url? /product_brand/brand_name/...