store custom WP table names in a global variable

The DB_ constant prefix in WordPress is generally considered reserved for DB_NAME, DB_HOST, DB_USER and DB_PASS. Using it for plugin-specific constants is, in my opinion, not a great idea. The only implication it might pose is if other plugins try to use the constants, but that’s purely theoretical. The proper way to do this is … Read more

JavaScript, best way to use data from the loop

You can use WP_Query to get almost any post data out of your WordPress install. $sub_pages = new WP_Query( array( ‘post_parent’ => 3, ‘post_type’ => ‘page’ ) ); print_r($sub_pages->posts); This would get you the following: Array ( [0] => WP_Post Object ( [ID] => 94 [post_author] => 1 [post_date] => 2015-08-20 11:19:27 [post_date_gmt] => 2015-08-20 … Read more

What is the global $wp object used for?

It contains the main instance of the WP class, which is primarily responsible for parsing the request URL and querying the appropriate posts, as well as sending headers and handling 404s. It can be used for things like getting the current request URL. If it’s declared in a function but not used, it’s likely a … Read more

How to check if this is the nth instance of a given shortcode in a post

If you’re using a class, it would be class MyShortcode { static $instance = 0; function __construct($args = array()) { add_action( ‘init’, array(&$this, ‘init’) ); } function init() { add_shortcode(‘myshortcode’, array(&$this, ‘shortcode’)); } static function shortcode($atts) { //this is the code of your shortcode // you can increment your counter self::$instance++; } }

Multisite Installation: how do I setup global search?

I think the best way to do it is to index all the posts and search through them in database. This method should be the fastest when you perform a search because you can filter posts, create the pagination etc. Check this tutorial https://rudrastyh.com/wordpress/search-across-wp-multisite.html Another way is to to something with switch_to_blog() function – I … Read more