I am getting this error when I call this method $query->the_post();
. I am trying to get the post id to get the post meta data. Accessing the $post->ID
from global post
return the current page id, but I need the post id for searching purpose.
You can see the error as image here
function search_form_submit(){
$task_name = isset($_GET['taskname']) ? $_GET['taskname'] : '';
$meta_key = 'wp_tasks';
$args = array(
'post_type' => 'tasks',
'post_status' => 'publish',
'posts_per_page' => 5,
'meta_query' => array(
array(
'key' => $meta_key,
'value' => $task_name,
'compare' => 'LIKE',
),
),
);
$query = new WP_Query($args);
global $post;
if($query->have_posts()){
$query->the_post();
$data = get_post_meta($post->ID,$meta_key,true);
}
}
$tasks_obj = new tasks();
if($_SERVER['REQUEST_METHOD'] == 'GET') {
$tasks_obj->search_form_submit();
}
get_userdata()
is used insidesetup_postdata()
, which is used insidethe_post()
. Since it’s pluggabke you can’t use it beforeplugins_loaded
. Hence my question about the hook.