Questions tagged [functions]

A function is a sequence of program instructions that perform a specific task. It is packaged as a unit that can be used wherever the according task should be performed.

Filter by
Sorted by
Tagged with
0 votes
0 answers
19 views

Let current user know pending posts counts using wp_query

I'm working on a query to let a logged-in user know if the user has more than 5 pending posts. Here's what I ended up with: // Start the query $query = new WP_Query( array( 'post_type' => '...
user avatar
  • 173
0 votes
0 answers
13 views

How to remove/hide collapse menu for user/subscriber?

I want to remove/hide the collapse menu item from the dashboard for user/subscriber role only. I don't want to remove it from the admin dashboard. I am the code below to remove it entirely which was ...
user avatar
0 votes
0 answers
15 views

Uncaught Error : call to product id functions generate [closed]

Error SHOW : Fatal error: Uncaught Error: Call to a member function empty_cart() on null in C:\xampp\htdocs\demo\woocommerce\wp-content\plugins\stenter code hererive-wook-commerce\public\settings\tabs\...
user avatar
  • 1
0 votes
2 answers
18 views

Cannot get wpdb data (Error in a simple fuction) [closed]

I'm using Cryto Plugin and want to get coin price data from plugin db. For easy practice, I'm trying to get BTC data. <?php function get_coin_price($coin_symbol) { global $wpdb; $coin_price = ...
user avatar
0 votes
1 answer
11 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
24 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
  • 3
0 votes
1 answer
24 views

How to inherit field value from parent post into in child / sub post

I have created a custom post type, called 'centres'. This CPT is hierarchical, ie, I can create child pages under each custom post. Centre1 Location1 Contact1 Centre 2 Location2 Contact2 I've ...
user avatar
0 votes
0 answers
13 views

How to avoid saving empty data to sql while using add_meta_box

I'm trying not to save empty data (null) while using add_meta_box function. My code is /** * Register meta boxes. */ function hcf_register_meta_boxes() { add_meta_box( 'hcf-1', __( 'Hello Custom ...
user avatar
0 votes
0 answers
9 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
12 views

How to implement Polylang functions 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
0 votes
0 answers
16 views

How to make WooCommerce payment method field optional?

Here is my current code on a plugin. /** * Field Validation. */ public function payment_process() { if ( 'woo_bkash' !== $_POST['payment_method'] ) { return; ...
user avatar
0 votes
1 answer
16 views

How to assign php file(template) to several pages with same prefix page name/slug

Can I assign WP php file (specific template) to several pages with same prefix name/slug using (if is_page(){}) ? If it's possible it could be useful. Is there a php function to do like css selector : ...
user avatar
0 votes
0 answers
21 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
0 votes
0 answers
14 views

How to Display WooCommerce Product Price in WooCommerce Archive

I have created a custom function to display 2 custom fields (ACF) and the price of the product after the item in the WooCommerce Archive/Shop page. My Custom fields are show, but I am unable to get ...
user avatar
  • 106
0 votes
1 answer
21 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
  • 688
0 votes
0 answers
26 views

How to change text color depending on the number value (Using javascript)

I'm trying to change text on the table depending on the meta value I give (number). if meta value >= 7, number text on table changes to green. else if meta value >= 4, number text on table ...
user avatar
0 votes
0 answers
17 views

is_main_query() always returning false

I've built a Wordpress site using Oxygen builder. I'm using the 'Post Types Order' plugin to control the post order. I have an Archive Page for a custom Post Type. For the Loop/Oxygen Repeater I'm ...
user avatar
  • 101
-1 votes
0 answers
14 views

how to limit search to post titles and contents by functions code?

Is there a way to limit search to post titles and contents? I tried below code in the link and its working but its just for titles. I would like to have function code for titles and contents. how to ...
user avatar
-2 votes
0 answers
12 views

limit search to post titles update the code for WordPress 5.9.3 [closed]

Hi Please update this code for WordPress 5.9.3 many thanks how to limit search to post titles?
user avatar
0 votes
0 answers
21 views

Change the behaviour of a button

I'm using Flatesome theme and I have a use case that I need to refresh the page after closing the popup, I'm wondering if I can change the behavior of the close button in Lightbox Popup so instead of ...
user avatar
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
1 answer
67 views

How to get an attachment id from a filename

I have not been able to find a reliable solution for how to lookup the id for attachments in the media library from a filename as Wordpress does not appear to provide such a function. Most solutions ...
user avatar
  • 79
-1 votes
0 answers
24 views

My enqueue javascript dont work?

This is my code in funcions.php wp_register_script( 'revaction', get_template_directory_uri() . '/extensions/revolution.extension.actions.min.js', ['jquery'], false, true ); wp_enqueue_script( '...
user avatar
0 votes
0 answers
12 views

Woocommerce Variable Product Dropdown for Custom Shop Template

I'm building out a custom shop template and I'm trying to achieve something like this. Where the user can choose the product variation in the dropdown, choose quantity, and click add to cart without ...
user avatar
0 votes
0 answers
21 views

Is this a backup door?

So I am working on client's site and I found this code in the functions.php file highlighted as a virus. @!!!>$user_search->query_where=str_replace('WHERE 1=1',"WHERE 1=1 AND{$wpdb->...
user avatar
  • 1
0 votes
1 answer
17 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
27 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
11 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
0 answers
15 views

Get Posts List of Current Selected Custom Taxonomy in Shortcode

I have a custom taxonomy called Album Link (album_link). I created this so I could link all music that has the term e.g (Glorious Album) to an album post type that uses the same term. The goal here is ...
user avatar
0 votes
0 answers
20 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
23 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
12 views

Create Custom URL structure for specific Post category using Post ID instead of post name

My Custom Structure is set to "%postname%/" This works as expected, but for Posts with the Category "Latest News", I would like to change the URL structure to be "%postid%/&...
user avatar
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
1 answer
33 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
17 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
51 views

Include widget file in functions.php of child theme

I've created a widget for WP 5.9.3, based on an online tutorial, which I'd got working okay, but it relied on having all the code in the child theme's functions.php, which started looking a bit messy. ...
user avatar
  • 101
0 votes
1 answer
17 views

Get Comma Seperated Taxonomy Linked Terms and Last Child Separated By "&" Instead Of Comma

I Want to List Custom Taxonomy Terms with Link and Separate Each with Comma but add "&" before the last term. Example: Drake, Migos, Ciara & Nicki I found this answer that shows ...
user avatar
0 votes
1 answer
17 views

How can I add a filter for specific categories on functions.php?

Hi, I am on functions.php and I want to add this filter: function graphene_alter_the_query( $request ) { $dummy_query = new WP_Query(); $dummy_query->parse_query( $request ); if (!...
user avatar
  • 133
0 votes
0 answers
16 views

Wordpress comment processing . Default unapproved comments detection before posting

I am working on wordpress comment section. I understand that when we are posting some comments for example comments with many links, then WordPress storing this comment in to the database with ...
user avatar
  • 25
0 votes
0 answers
15 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
9 views

Astra theme - cannot set short product description under the product title (product name)

I want to have following vertical structure on my products short description: Image->Product Name->Short Description. I've read that by default it is this order. This is the code I'm using: ...
user avatar
  • 1
1 vote
2 answers
42 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
1 vote
0 answers
18 views

Display alert on successful user Sign Up

I think wordpress used to automatically redirect to a page with a message telling a newly registered user to check their email box to activate their account. For some reason, when a new person ...
user avatar
  • 123
0 votes
1 answer
27 views

Warning at top of website & top menu gone

This warning has appeared at the top of our website, and our top menu bar has disappeared: Warning: call_user_func_array) expects parameter! +~ be a valid callback, function '...
user avatar
0 votes
1 answer
19 views

Featured Image and Tags problem

I am very new to PHP and am having an issue with an amazing advanced Wordpress tutorial which showed how to use ACF and functions.php to scrape and import the data directly into my Animal Shelter ...
user avatar
1 vote
0 answers
23 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
23 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
14 views

Is posible to redirect a few URL?

i'm making this website using wordpress as headless and using gatsby in the front-end, i pass the information using the api I have the wordpress in a URL example ap-backend.com and the front-end in ...
user avatar
  • 9
0 votes
0 answers
26 views

Need help making a short code work

I will try to explain my question as good as possible. but since english is not my main language I hope you will understand. Im trying to fill a carrousel with a custom post type. if got everything ...
user avatar
  • 1
0 votes
1 answer
35 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

1
2 3 4 5
112