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

WP-API v2 Custom Endpoint Response Formatting

You can call the REST API methods to prepare your output in the same way that the plugin does by default, this will also allow any plugins to tie into the output as you have used the ACF plugin as seen in your example output. The WP_REST_Posts_Controller class has the following in its get posts … Read more

How can I fetch loop of post titles via AJAX?

you can wrap your function and hook it to ajax call like this: //if you want only logged in users to access this function use this hook add_action(‘wp_ajax_more_links’, ‘my_AJAX_more_links_function’); //if you want none logged in users to access this function use this hook add_action(‘wp_ajax_nopriv_more_links’, ‘my_AJAX_more_links_function’); function my_AJAX_more_links_function(){ check_ajax_referer(‘more_links’); $success_response = new WP_Ajax_Response(); $args = array(‘posts_per_page’ … Read more

What is the best php version to use with WordPress?

There isn’t (and shouldn’t) be an answer with any specific version for this. New versions come out, old versions get discontinued. At the minimum you should use supported version of PHP. This ensures it still receives bug fixes and (or for less recent version) security updates. Preferably you should be use the latest stable version … Read more

Disable Attachment Pages Completely

You can filter default rewrite rules and remove those for attachments: function cleanup_default_rewrite_rules( $rules ) { foreach ( $rules as $regex => $query ) { if ( strpos( $regex, ‘attachment’ ) || strpos( $query, ‘attachment’ ) ) { unset( $rules[ $regex ] ); } } return $rules; } add_filter( ‘rewrite_rules_array’, ‘cleanup_default_rewrite_rules’ ); Don’t forget to … Read more

add_action in namespace not working

Before going too far down this path I would suggest that you familiarize yourself with PHP name resolution rules. To answer your actual question – When you namespace functions, the fully qualified name of those functions includes the namespace. In your example, you have defined two functions: \myPlugin\add_activation_notice and \myPlugin\activation_notice. When calling either of these … Read more

Uploading media with the REST API

This is not possible via the API; you need to fetch the image yourself, and send the data to the API yourself. Blockquote – This quotes Ryan on the GitHub–issue mentioned in @Dan (deleted) answer. How to side load images Note that the media_sideload_image() return value can be an instance of \WP_Error as well. You … Read more

How to change upload directory in wp_handle_upload

Here’s a complete example for how we do it in Easy Digital Downloads: /** * Set Upload Directory * * Sets the upload dir to edd. This function is called from * edd_change_downloads_upload_dir() * * @since 1.0 * @return array Upload directory information */ function edd_set_upload_dir( $upload ) { $upload[‘subdir’] = ‘/edd’ . $upload[‘subdir’]; $upload[‘path’] … Read more

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş