Fatal Error in wp_get_current_user() Function

You call this function too early, before pluggable function is_user_logged_in() is defined. Try this: function wpse_get_current_user() { $current_user = wp_get_current_user(); // do other stuff here } add_action( ‘init’, ‘wpse_get_current_user’, 10 );

Sanitizing text fields in array

The best way to sanitize text fields within WordPress is to use sanitize_text_field() function: $data = sanitize_text_field( $_POST[‘key’] ); Additionally, if you register the meta field properly width register_meta() function, you can define the sanitize callback and the expected data type as well. For example: add_action( ‘init’, ‘cyb_register_meta_fields’ ); function cyb_register_meta_fields() { $args = array( … Read more

get the correct url for an folder in wp-includes wordpress

You sad you put the json in wp-includes, but in the url you wrote wp-content. So I give you the code for getting the server path for both folders: // wp-includes $file = ABSPATH . WPINC . ‘/json/users.json’; // wp-content $file = WP_CONTENT_DIR . ‘/json/users.json’; You can find many WordPress constants (like ABSPATH, WPINCand WP_CONTENT_DIR … Read more

wp ajax return 0

There’s a simple alternative that sidesteps this issue entirely with a modern and easy to use interface, just use a REST API endpoint! So lets turn this: add_action(‘wp_ajax_nopriv_linked_post_image_grid’, ‘linked_post_image_grid’); add_action(‘wp_ajax_linked_post_image_grid’, ‘linked_post_image_grid’); function linked_post_image_grid(){ echo ‘this is return message’; die(); } Into this: add_action( ‘rest_api_init’, function () { register_rest_route( ‘buxbeatz/v1’, ‘/linked_post_image_grid/’, array( ‘methods’ => ‘GET’, ‘callback’ … Read more

Odd / Even posts add class minus first post

You can do this in multiple ways, but you will need something commom to all posts, exemple: <div class=”post”></div> <div class=”post”></div> <div class=”post”></div> <div class=”post”></div> <div class=”post”></div> then in your css: .post:not(:first-child) { // add the rules of the class you wanted to add } Just select all elements except the first-child of posts with … Read more

How to convert select to HTML with PHP tags inside of it [closed]

An example: your code <option value=”0″ ‘ .selected($horizon_featured,’normal’,false) .’>Descending</option> HTML code with some PHP mixed in: <option value=”0″ <?php echo .selected($horizon_featured,’normal’,false); ?>>Descending</option> Basically, you just put a <?php echo $something;?> where you want the PHP stuff to be.

Can we count the WordPress Loop

$wp_query->current_post is the build-in loop counter, starting with 0 zero for the first post in the loop. so the line some code to be executed could translate to: <?php if( $wp_query->current_post > 0 && $wp_query->current_post % 5 == 0 ) { ?> some code to be executed <?php } ?>