Include WP_Query in my own PHP file?

Load WordPress in custom PHP Script: You need to load essential WordPress core functionality in your custom PHP script for WP_Query to work properly. For example, let’s say you have a custom PHP file named my-cron.php and WordPress is installed in the web root, like this: public_html/ index.php my-cron.php <– wp-load.php wp-settings.php … wp-admin/ wp-content/ … Read more

How to include a plugin’s php file to another plugin functions file [duplicate]

The first error message means that there is restrictions in place on where you can include files from, set by the server. You could try with require_once ABSPATH . ‘/wp-content/plugins/pluginname/pluginfunctions.php’; but I’m not sure if it would work. With the second include you’re trying to include an URL which is disabled by the server for … Read more

is_plugin_active() returning false on active plugin

is_plugin_active() expects just the base name of the plugin as parameter: So use: is_plugin_active( ‘woocommerce/woocommerce.php’ ); The function will use the option ‘active_plugins’ which is a list of plugins paths relative to the plugin directory already. On a multi-site installation it will search in get_site_option( ‘active_sitewide_plugins’) too. As an implementation note: Avoid these checks. Some … Read more

Should we use get_template_part() in functions files instead of include_once?

Your functions.php doesn’t create output, so you should use locate_template(). Example: locate_template( ‘php/functions.nav-menu.php’, TRUE, TRUE ); You’ll find this function in wp-includes/theme.php. The first parameter is the file path relative to the theme root, the second tells WordPress to load it (or not), and the third to load it just once. Now a child theme … Read more

The proper way to include/require PHP files in WordPress

If you check https://codex.wordpress.org/Function_Reference/get_template_directory_uri You will see get_template_directory_uri() returns a uri, not a server path. You should use instead the get_template_directory() function: include get_template_directory() . ‘subdir/filename.php’; For a plugin you can use the plugin_dir_path() function: include plugin_dir_path( __FILE__ ) . ‘subdir/filename.php’;

Is there any way to use get_template_part() with folders?

In fact you can, I have a folder in my theme directory called /partials/ in in that folder I have files such as latest-articles.php, latest-news.php and latest-statements.php and I load these files using get_template_part() like: get_template_part(‘partials/latest’, ‘news’); get_template_part(‘partials/latest’, ‘articles’); get_template_part(‘partials/latest’, ‘statements’); Just dont forget to omit the .php from the file name.

Passing variables through locate_template

Like MathSmath wrote, get_template() does not support the re-use of your variables. But locate_template() infact does no inclusion at all. It just locates a file for inclusion. So you can make use of include to have this working just like you expect it: include(locate_template(‘custom-template-part.php’)); $var from your example can be used in the template part … Read more

get_template_directory_uri pointing to parent theme not child theme

get_template_directory_uri() will always return the URI of the current parent theme. To get the child theme URI instead, you need to use get_stylesheet_directory_uri(). You can find these in the documentation, along with a list of other useful functions for getting various theme directory locations. If you prefer to use a constant, then TEMPLATEPATH is akin … Read more