I want to check if user is logged in and if have created a page. If so, option 1 is shown. This all works fine.
But how to display page title+link of page created by that user between {page title with link to page}
See the code below I tested it with no results. As used in the code below, nothing special is showing, only option 1 text (which is good for the user have a page created and is logged in).
<?php
if ( is_user_logged_in() ) {
global $wpdb;
$user = wp_get_current_user();
$where = get_posts_by_author_sql( 'page', true, $user->ID );
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
if ( $count >= 1 ) {
// this part is added to display page title+link created by current user
foreach ( $results as $result )
printf( '<a href="%1$s">%2$s</a><br>',
get_permalink( $result->ID ),
esc_html( $result-post_title )
); ?>
//option 1
<h2>Hey <?php echo $current_user->display_name ?>, check your page here: {page title with link to page} </h2>
<?php } else { ?>
//option 2
<h2>Welcome <?php echo $current_user->display_name ?>, etc.. text with tags etc.</h2>
<?php } } else { ?>
//option 3
<h2>text with tags etc.</h2>
<?php } ?>
Any suggetions?