Is there any way through which I can declare the dynamic variable in php. for eg, I am using a for loop and the variable name is $message. and I want to add some dynamic data at the end of the variable name. code is below foreach ($quant as $quantity) { $message.$quantity['type'] = 'Listing ID : '.$quantity['product_id'].' With Quantity: '.$quantity['quantity'].'MT, State- '.$quantity['state_name'].' and Coal type-'.$quantity['coal_type'].'<br>'; } so if the $quantity['type'] = 1, then the variable name should be $message1 and …
I bought a Theme which unfortunately has some static content, I managed to hide and remove some via editing and the custom css. But I have a text field above the navigation where it says "Work Time" I need a way to write the German and English version of that text somewhere in my WP-Admin panel and tell the theme to load selected language text into that text field. I have coded some stuff in php js and mysql so …
Woocommerce subscriptions | All Products for WooCommerce Subscriptions Does anyone know if there's a way to disable the subscribe option for a specific product variation? i.e. product with 2x attributes: attr-1, attr-2 All of which can be bought singly or via a sub on the PDP, is there a way to disable the subscribe option for one of the attributes? There's no succinct way using the wcsatt_product_subscription_scheme filter without a lot of JS logic. Have reached out to WC and …
I have a custom loop for showing child pages of the current page, but I'd like to allow the WP user to enter page IDs to be excluded from the loop, using Advanced Custom Fields. My current loop is as follows. It almost works, except it only excludes the first page ID in the list: <?php $exclude_ids = get_field('exclude_pages'); $args = array ( 'post_type' => 'page', // custom post type 'post_parent' => $post->ID, 'orderby' => 'menu_order title', 'order' => 'ASC', …
I have created a wordpress website. I want to extract each user's data using php through his/her id. I have created this code; <?php $userid = /* help me get the below input field's value */ $user_info = get_userdata($userId); echo 'Username: ' . $user_info->user_login . "\n"; echo 'User roles: ' . implode(', ', $user_info->roles) . "\n"; echo 'User ID: ' . $user_info->ID . "\n"; ?> <input name="getUser" id="getUser" value=''/> The user will write the id of the user he wants …
I have following code in my plugin of Wordpress: wp_localize_script('ffd_js_script', 'myAjax', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'idinfo' => $myoptionValue[idinfo], 'index1' => $myoptionValue[id1], 'index2' => $myoptionValue[id2] ) ); I want to replace 'index1' => $myoptionValue[id1], 'index2' => $myoptionValue[id2] with for($i=1; $i<= $myoptionValue[fieldcount]; $i++) { $arguments .= ',"index"'.$i.'=>'.$myoptionValue[id.$i]; } So that I have wp_localize_script('ffd_js_script', 'myAjax', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'idinfo' => $myoptionValue[idinfo] $arguments ) ); Apparently I'm thinking it might be as simple as this, but it isn't, where is my mistake? EDIT: …
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() { global $pixelcapival; $pixelcapival = pixelcapival(); global $prev_pixelcapival; $prev_pixelcapival = ''; if(isset($_COOKIE['pixelcapival'])) { $prev_pixelcapival = $_COOKIE['pixelcapival']; } setcookie('pixelcapival', $pixelcapival, time() + 1200, '/'); } I can now get access to $pixelcapival from the previous pageview by global $prev_pixelcapival But if any ajax-calls are being made in between, i guess the ajax-call triggers the init-action, and …
For exercise I am working through a PHP class to add meta boxes I found on GitHub. I just copied the code and now I am playing around with it to understand it. It works like this: The file containing the class is included on init. Inside that file, but outside the class, an empty array $meta_boxes is initialized. After that, a custom action is executed, using apply_filters. My guess is apply_filters is used instead of do_action because the latter …
I am creating a widget that handles order numbers. The basic structure is as follow: // pretty generic widget functions public function widget($args, $instance) { $order_number = $instance['order_number']; } public function update($new_instance, $old_instance) { $instance = $old_instance; $instance['order_number'] = strip_tags($new_instance['order_number']); } public function form($instance) { if ($instance) { $order_number = esc_attr($instance['order_number']); }else { $order_number = ''; } what I usually do is to ask the user for the order number. Like this: <input name="<?php echo $this->get_field_name('order_number'); ?>" type="text" value="<?php echo …
I have an API Request for weather and the account of this weather stuff has a limitation of requests per minute. In my theme I have the weather information twice on the same page. So if I would make a function of the request it would fire twice. I thought about a global variable, where I could save the request once and grap this variable where ever I want. Is this a good idea? I read something about, that global …
I have a search results page and on the page, I would like to be able to filter by category. So when the user searches an item, it gets passed to the results page in the url like: website.com/?s=example What I would like to do is take the value of "s" and use it in a link to another page. What I am thinking is doing something like this: $_searchquery = $_GET['s']; Then adding the $_searchquery variable to the url …
Ultimately to keep it real simple, on a custom query page, I have a global variable that I pull from a previous page. When I go to page 2… the global variable is blank. Page 1: Define global variable. Link to another page Page 2: When on page 2, i call global variable, it works fine On this page 2, it is a custom query. When I go to page 2, the global variable is now blank. It seems the …
I have a shortcode from a plug-in called Pods that is used like [pods-form name="user" id="" fields="my_field, my_field_2, my_field_3"] Parameter name contains the name of the custom post type (here: enhanced the WP user post type). Parameter id now shall receive the user ID of the currently logged in user. The page containing this shortcode is only available to logged-in users. How to add the current user ID as a variable to this shortcode? I'm looking for something like this …
I am developing a custom search where the user inputs data on the first page with a form. Upon clicking submit, the user is brought to a second page for the results. I pass the data via pulling in the form results via $_POST. Then assigning it to a $_SESSION. It works great… until I hit the next button to go to page 2. The pagination works fine, but the issue is that the variables do not load on the …
I am creating a Plugin that displays e-mails as posts. I used the following PHP to access those emails: <?php class Email_reader { // imap server connection public $conn; // inbox storage and inbox message count private $inbox; private $msg_cnt; // email login credentials private $server = 'website.com'; private $user = '[email protected]'; private $pass = 'PASSWORD'; private $port = 993; // adjust according to server settings // connect to the server and get the inbox emails function __construct() { $this->connect(); …
I'm using set_query_var to bookmark snippets that were already published, in order to exclude them from other independent loops on the page. Basically, so that no title ever comes up twice. Basically something like... set_query_var('exclude', $post->ID); ...and later... 'post__not_in' => get_query_var('exclude'); The problem is that the function updates the field every time, so if I run it in a loop it would become next to useless. So I came up with this function: function update_query_var($name,$value) { $oldvalue = get_query_var($name); if(is_array($value)) …
I need to send a private e-mail address from a php file (page.php) to an Ajax Call in an other jquery file (sender.js). This e-mail address must be invisible to user/or website until the user get an automatic response from wp_mail, It must allowed it to answer to the organization. This e-mail address is different according to the organization that the client want to contact (several hundred). I'm obliged to get the e-mail address from organization before form because it …
I have created a form that posts user input to an API, in my function I have multiple Posted Data entries that take the value from my user input. In my $body variable I have set it to receive the API response after my API is sent, but now I want this response to be shown in my user inputs $body = $posted_data['dynamichidden-458']; I have $body that receives the API response in $body = $posted_data['dynamichidden-458']; I want my API response …
From our CRM I can generate URL's for customers that includes parameters. I want to use the information stored in this parameters to show dynamic content to the customers. Example: www.example.com/page/?firstname=John&lastname=Doe&age=22 I need to display this information as the following: Firstname: John Lastname: Doe Age: 22 For this I used the following code in my functions.php <?php function dynamicParameters($atts){ //Allow to call a parameter within a shortcode $a = shortcode_atts( array( 'dynamic' => ''), $atts); //Store the parameter in variable …
Having trouble finding info on this. When working with lots of metadata/custom fields, I would really prefer to simplify getting the meta data inside of templates instead of using get_post_meta and instead keep the setting up of that data in the back-end where it belongs to keep my templates clean and easier to work with. Is there a way to do this? <p><?php echo $something->meta_field_name ?></p> This would be similar to how you can do things like $post->ID or $post->post_parent …