Skip to content

Instantly share code, notes, and snippets.

@drahcirwalsh
Last active October 17, 2018 00:11
Show Gist options
  • Select an option

  • Save drahcirwalsh/a0a9d4fe15b4e83e1892d47cb72382ce to your computer and use it in GitHub Desktop.

Select an option

Save drahcirwalsh/a0a9d4fe15b4e83e1892d47cb72382ce to your computer and use it in GitHub Desktop.
<?php
function list_posts_for_edit(){
if(is_user_logged_in()){
$args = array(
'post_type' => '****POST_TYPE_HERE****',
);
$posts = new WP_Query($args);
if($posts->have_posts()){
$results = '<ul>';
while($posts->have_posts()){
$posts->the_post();
$title = get_the_title();
$id = get_the_id();
$results .='<li><a href="' . site_url() . '/PATH_TO_EDIT_PAGE/?post=' . $id .'" class="edit_post_link">
' . $title .'</a>
</li>';
}
$results .="</ul>";
return $results;
wp_reset_postdata();
}
else return 'There are no posts.';
}
else return 'You must be logged in to access this page';
}
add_shortcode('list_editable_posts', 'list_posts_for_edit');
?>
/**
* Add to Page Template
**/
<?php
if(is_user_logged_in()){
if($_GET['post'] != ''){
$post = $_GET['post'];
advanced_form( '****FORM_ID_HERE****', array( 'post' => $post ) );
}
}else return 'You must be logged in as an administrator to access this page';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment