So inside my plugin I have the following code. It gets a question from a custom_post. I'm processing it here so that further updates can be done by AJAX/JSON and the page only has to be configured for one type of data source.
$observations = new WP_Query($args);
if ( $observations-> have_posts() ) :
$questionpost = $observations->posts[0];
$question = array (
'id' => $questionpost->ID,
'title' => $questionpost->post_title,
'name' => $questionpost->post_name,
'excerpt' => $questionpost->post_excerpt,
'content' => $questionpost->post_content,
'code' => get_post_meta( $questionpost->ID, 'code', true ),
'edit_link' => get_edit_post_link($questionpost->ID),
);
if ( has_post_thumbnail($questionpost->ID) ) {
$question['thumbnail'] = get_the_post_thumbnail( $questionpost->ID, 'full', array('class' => 'card-img-top'));
} else {
$question['thumbnail'] = get_template_directory_uri()."/img/no-image.png";
}
print_r($question);
}
It all works fine except for the get_edit_post_link - here is print_r dump:
Array ( [id] => 208 [title] => Main ... pipework. [name] => nr-60 [excerpt] => [content] => The ... external. [code] => NR [edit_link] => [thumbnail] => http://.../img/no-image.png )
https://codex.wordpress.org/Function_Reference/edit_post_link suggests we can pass an ID so I don't see why this is blank.