The tag has no usage guidance.

learn more… | top users | synonyms (1)

0
votes
2answers
25 views

Call global variable array() in woocommerce child/template

So I have this in my functions file - it defines the products that are not eligible for free shipping. It works everything is fine. //functions.php function my_free_shipping( $is_available ) { ...
2
votes
0answers
32 views

Global Objects and Public Methods

I'm developing a plugin and am just thinking over best practices. How common is it to have a global object? Currently on plugins_loaded I am creating a global object of my class: add_action( ...
1
vote
2answers
28 views

Custom plugin: Trying to show saved data on frontend

I'm working on my first plugin and I have made a nice settings page which saves and works. But I have split it to few files and now I can't determine if field is checked.. I have also tried ...
1
vote
2answers
35 views

Override global query results without hooks

I have a custom php page and i need to override the global posts variables, but i cant get it to work. When going through the main loop im able to override the global posts, but i cant override ...
1
vote
1answer
48 views

WP 4.4.1 allow empty comments via add_action 'pre_comment_on_post'

got a question about allowing empty comments with worpdress v.4.4.1 to achieve this i use the action 'pre_comment_on_post'. in WP 4.3.1 i could do this easily: if (isset($_POST['comment']) ...
0
votes
1answer
57 views

Retrieve post in AJAX Callback

I have a JS file that triggers a PHP callback file. The PHP file is supposed to work on the Post that is currently opened (wp-admin/post.php). I do not want the JS file to pass the post id though ...
8
votes
3answers
150 views

Any advantage of using wp_scripts and is_IE when enqueuing scripts

I read on the WP docs, which pointed to this gist that the correct way to enqueue styles for IE is by using the $wp_styles. I'm guessing that this would be true then for scripts as well. Take these ...
0
votes
1answer
7 views

Multisite Global Custom Posts

I have a museum client with a multisite setup with pages that detail the exhibits in their facility. They recently added tablets throughout the museum and want their tablets to display only their ...
0
votes
1answer
30 views

Declare global variable that can be used on other function

I have AJAX image upload function where I can get attachment_id value. I want to save that as global variable and use it in different function that sets post thumbnail when it's exist. This is what I ...
0
votes
1answer
19 views

Array is not working in Filter?

This doest not works: Warning: in_array() expects parameter 2 to be array, null given $non_area_page = array(160951,160955); // This does not work add_filter( 'term_link',change_term_name , 10, ...
0
votes
0answers
26 views

passing category name from category.php to single.php

It's the first time I used WP. I just use a small portion of it, because I already had my website ready. So the only section that uses WP is the blog section. I finally was able to implement it has ...
0
votes
2answers
133 views

after_setup_theme, global variable and Theme Customizer

I am using a global variable that is defining in a function runs in after_setup_theme. This variable is not getting update changes in Theme Customizer. Let me explain this with an example: ...
3
votes
2answers
54 views

Accessing $post global on a custom post type archive page

I have a custom post type called projects, and its archive is at /projects, on the archive page I get notices Notice: Trying to get property of non-object every time I try to access the $post i.e. ...
0
votes
2answers
64 views

How do I pass custom shortcode-extracted variables (taxonomy) into a query function for WordPress RoyalSlider?

Plugin in question: http://dimsemenov.com/plugins/royal-slider/wordpress/ Background: This is a great plugin, and it features a 'post' version where the slider pulls content from posts. However, the ...
1
vote
1answer
63 views

JavaScript, best way to use data from the loop

I am trying to learn WP theme development. And at the moment I am trying to figure out how to use data from the loop in JavaScript. Lets say I got some JavaScripts functions in a external script-file ...
0
votes
2answers
21 views

Save last login date in global before change it?

I use this function to get the last time a user logged in. function jkn_last_login($user_login) { $user = get_user_by( 'login', $user_login ); global $last_login; $last_login = array(); ...
0
votes
0answers
230 views

Wordpress ajax load more returns duplicated posts

I'm trying to load more posts from my custom post type via ajax call, it sounds like i'm doing everything alright but one thing which is causing the duplication issue. My load more button does work ...
0
votes
1answer
27 views

apply_filters to $GLOBALS

I'm building a onepage website, using the Pootle Page Building plugin. With get_page, I show every separate page on 1 page. To target the Pootle Page Builder content, I'm using the following code: ...
0
votes
0answers
16 views

Can't access global scope in widgets

How to set global/static variable inside of a widget function of a widget? I use this code: class MY_Widget extends WP_Widget { function widget( $args, $instance ) { global $myvar; ...
0
votes
0answers
223 views

Setting a cookie in functions.php and it gets deleted when working on an other function

My first function gets the parameters from the URL and sets the cookies: /** Get variables from the URL and set them into the coockie **/ add_action( 'init', 'set_utm_cookie'); function ...
0
votes
0answers
47 views

Popup panel is only displaying 1 entry ignoring all others

I have a popup panel being used for when someone clicks on view bio it will display their bio along with their name and headshot. As of right now I have four members being displayed M1 M2 M3 and M4. ...
0
votes
0answers
46 views

Best way to access variables in template markup

I am making my own mini OOP wrapper for working with wordpress themes. I have a main $settings variable that contains all of the information like definitions, scripts, menus etc.. I then pass this ...
0
votes
0answers
15 views

Retrieve the real time widget area class

I'm trying to retrieve programmatically the sidebars classes in my developed pluging. I use the global $GLOBALS['wp_registered_sidebars'][1] and try to access the 4th element(class) in the array but I ...
0
votes
1answer
150 views

'global' not working in wordpress?

My wordpress theme consists of the file loop.php which just does this: <?php include("AAAA.php"); ?>. Now AAAA.php looks like this: <?php $test = 1; function f() { global $test; ...
0
votes
1answer
57 views

Editing Global Variables from Inside Functions

I'm working on my first plugin and I have two separate functions inside to accomplish two different task. Each function is added to a different hook, one using actions and the other using filters. ...
7
votes
3answers
372 views

Reducing the use of global $post

When creating meta boxes, in each meta box function it seems a reference to the global $post is passed as a parameter ($event). I prefer this as it seems consistent and less likely to fudge the $post ...
0
votes
1answer
670 views

how to load posts to a custom post template after using template_redirect or template_include

I need to use the URL parameter ?m=1 to load every page of my wordpress with a different template but the problem is that I can't pull the text and posts that can be accessed using the canonical URL I ...
0
votes
2answers
97 views

Global Variable vs Local Variable

// MOVE REVISIONS METABOX TO BOTTOM OF EDIT-FORM.PHP $post_types = get_post_types(); add_action('do_meta_boxes', 'batteryboys_reorder_meta_boxes'); function batteryboys_reorder_meta_boxes(){ ...
1
vote
1answer
132 views

Add classname comment template from functions.php

I want to add an extra classname to my comment template (the div wrapper before the post itself) which is stated in functions.php. The classname in functions.php is an extra field in my users profile ...
3
votes
2answers
1k views

When to use global $post and other global variables?

I am trying to understand when and why I should use the global $post variable. I have tried to do the following on a post page, outside the loop, and as expected it works. <?php ...
0
votes
1answer
18 views

Settings in functions.php used by a plugin

I'm writing a simple plugin and want some settings in an array in the functions.php file. I'm thinking of adding this in the theme functions.php $test = array('haha' => 'hehe'); my_function( ...
12
votes
1answer
251 views

Should we trust the post globals?

@toscho left a comment to this answer which had me thinking again. How much trust should we have in the global scope, specially regarding the post globals like $post? So what? The global variable ...
0
votes
1answer
59 views

Use a variable created in get_header to calculate stuff in wp_footer

i am trying to create a small time tester that loads at get_header hook and the using the value does something in wp_footer... i have tried using global $var i tried putting the global var inside ...
2
votes
2answers
296 views

When and Where is `global $post` Set and Available?

Usually when people think of the global $post object it's assumed that it's actually set whenever you enter The Loop. I started to play around with how early I could actually call global $post which ...
0
votes
0answers
136 views

Using custom fields globally?

I'm trying to use the value of one custom field on multiple pages and posts. I'm a newbie to PHP and custom fields so what I'm trying to accomplish could possible be done using a different method. I ...
0
votes
0answers
126 views

How to load post_meta for custom post type via Ajax

I'm trying to load a YouTube video via ajax outside the loop. I have it working on regular pages, but not anything loaded via ajax. A user would click a button, then a YouTube video will load via ...
4
votes
2answers
270 views

Why declare $post globally?

I'm new to Wordpress development and am seeing examples everywhere that have a line to declare the $post variable explicitly via: global $post; But I've tested my uses without that line and it ...
0
votes
1answer
335 views

how to get the post id in plugin

I have a plugin that I'm working on and I'm having trouble getting the post id so jquery can use it. I'm able to get it using the admin_head hook but I'm not sure how I can return it to jquery. I'm ...
0
votes
0answers
60 views

Sessions in plugin development?

I'm developing a plugin. At present I have two files. dotmailer.php and dotmailer-add.php. I'm creating a newsletter widget. My dotmailer.php plugin adds an admin menu, with options. It allows the ...
0
votes
1answer
236 views

Access post ID in “content_save_pre”

First time poster, pardon my mistakes. I am trying to use the content_save_pre filter to grab a URL in the first line of a post and save it into a custom meta, and also set the post format as a link. ...
1
vote
1answer
392 views

How to access global $wp_meta_boxes variable on front-end?

Is there a way to take the global $wp_meta_boxes variable to be used in the front-end? Currently the $wp_meta_boxes is accessible on specific admin pages only. I've found a similar question about ...
2
votes
1answer
2k views

Passing variables from header.php to template and vice verca

I've defined a variable - let's call it $header_var, which is placed in the header.php file. I would like this variable to be passed onto my template file (in this case taxonomy.php). Also I would ...
0
votes
1answer
136 views

store custom WP table names in a global variable

I was being creative and put this in one of the files loaded with my plugin. Are there implications with storing the table names this way? global $wpdb; if(!defined('DB_ARTISTS')) ...
0
votes
0answers
13 views

setting global and using as argument [duplicate]

I've set a global variable in functions.php like so: $cat_args = array('cat1', 'cat2', 'cat3'); and tried to use it in a template file: global $cat_args; if is_cat($args): //do stuff endif; The ...
0
votes
1answer
712 views

Cannot update custom database table row

I am trying to update a row in a custom database table by $wpdb->update();. In my opinion my code is right but for some reason my database row doesn't update. Can anyone help me with this? I want ...
0
votes
1answer
184 views

Php file that doesn't recognize wordpress functions

I have a custom contact form that I am trying to process in other file: The form: <form method="post" action="<?php echo get_template_directory_uri() . '/templates/contact.php' ?>" ...
2
votes
2answers
1k views

Should I global $wpdb outside of any of my plugin's functions scope?

I know that the general advice to global variables is to not use them at all. Still, when doing something with the Wordpress database, it is required to do global $wpdb; to access the methods ...
0
votes
1answer
73 views

Understanding WordPress Search

I am trying to create a custom search similar to the one on totaljobs.com but through a WordPress site. Essentially I would be able to search for both search terms and location simultaneously. The ...
0
votes
1answer
217 views

Current URL path variable

WordPress has a built-in variable $pagename that will give the current page. I am looking for something that will give the full url including the path before the current page. Details below. I am ...
1
vote
2answers
3k views

Using global $post; to get featured image for custom post via WP_Query

I'm using a site-wide function to add css to the <head> of the page pull in featured images of various as a responsive page background. It works great across the rest of my site but fails on a ...