Skip to main content

I have an author page, iand I want to list postposts from current author's categories.

e.g. ImI'm viewing John's page, and John did writewrote in Sport, Tech, News, Computer categorycategories.

Then my code list from this  (Sport, Tech, News, Computer) categories list random 10 post.

But something is going wrong,:

Im viewin an author page, author written 4 category andThose 4 categorycategories have 25 postposts.But But my code notisn't listing 10 posts, it's just listing 1 post. And i need random post list

Regards

My code:

<?php global $post, $wpdb;
$author_id = $post->post_author;
$categories = $wpdb->get_results("
    SELECT DISTINCT(terms.term_id) as ID, terms.name, terms.slug
    FROM $wpdb->posts as posts
    LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID
    LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id
    LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id
    WHERE 1=1 AND (
        posts.post_status = 'publish' AND
        posts.post_author = '$author_id' AND
        tax.taxonomy = 'category' )
    ORDER BY terms.name ASC
");

foreach($categories as $category) : 
    $catnumber = $category->ID.',';
endforeach;?>
<?php 

$args = array(
'category__and' => array( $catnumber )
, 'showposts'=> '10'
);

$my_query = new WP_Query( $args );
?>
<ul>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>  
    </li>
<?php endwhile; ?>
<ul>
<?php wp_reset_postdata(); ?>

I have an author page, i want to list post from current author's categories.

e.g. Im viewing John's page, and John did write Sport, Tech, News, Computer category

Then my code list from this(Sport, Tech, News, Computer) categories list random 10 post.

But something going wrong,

Im viewin an author page, author written 4 category and 4 category have 25 post.But my code not listing 10 posts just listing 1 post. And i need random post list

Regards

My code

<?php global $post, $wpdb;
$author_id = $post->post_author;
$categories = $wpdb->get_results("
    SELECT DISTINCT(terms.term_id) as ID, terms.name, terms.slug
    FROM $wpdb->posts as posts
    LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID
    LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id
    LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id
    WHERE 1=1 AND (
        posts.post_status = 'publish' AND
        posts.post_author = '$author_id' AND
        tax.taxonomy = 'category' )
    ORDER BY terms.name ASC
");

foreach($categories as $category) : 
$catnumber = $category->ID.',';
endforeach;?>
<?php 

$args = array(
'category__and' => array( $catnumber )
, 'showposts'=> '10'
);

$my_query = new WP_Query( $args );
?>
<ul>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>  
    </li>
<?php endwhile; ?>
<ul>
<?php wp_reset_postdata(); ?>

I have an author page, and I want to list posts from current author's categories.

e.g. I'm viewing John's page, and John wrote in Sport, Tech, News, Computer categories.

Then my code list from this  (Sport, Tech, News, Computer) categories list random 10 post.

But something is going wrong:

Those 4 categories have 25 posts. But my code isn't listing 10 posts, it's just listing 1 post. And i need random post list

My code:

<?php global $post, $wpdb;
$author_id = $post->post_author;
$categories = $wpdb->get_results("
    SELECT DISTINCT(terms.term_id) as ID, terms.name, terms.slug
    FROM $wpdb->posts as posts
    LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID
    LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id
    LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id
    WHERE 1=1 AND (
        posts.post_status = 'publish' AND
        posts.post_author = '$author_id' AND
        tax.taxonomy = 'category' )
    ORDER BY terms.name ASC
");

foreach($categories as $category) : 
    $catnumber = $category->ID.',';
endforeach;?>
<?php 

$args = array(
'category__and' => array( $catnumber )
, 'showposts'=> '10'
);

$my_query = new WP_Query( $args );
?>
<ul>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>  
    </li>
<?php endwhile; ?>
<ul>
<?php wp_reset_postdata(); ?>
added 195 characters in body
Source Link
Genxer
  • 195
  • 1
  • 11

I have an author page, i want to list post from current author's categories.

e.g. Im viewing John's page, and John did write Sport, Tech, News, Computer category

Then my code list from this(Sport, Tech, News, Computer) categories list random 10 post.

But something going wrong,

Im viewin an author page, author written 4 category and 4 category have 25 post.But my code not listing 10 posts just listing 1 post. And i need random post list

Regards

My code

<?php global $post, $wpdb;
$author_id = $post->post_author;
$categories = $wpdb->get_results("
    SELECT DISTINCT(terms.term_id) as ID, terms.name, terms.slug
    FROM $wpdb->posts as posts
    LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID
    LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id
    LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id
    WHERE 1=1 AND (
        posts.post_status = 'publish' AND
        posts.post_author = '$author_id' AND
        tax.taxonomy = 'category' )
    ORDER BY terms.name ASC
");

foreach($categories as $category) : 
$catnumber = $category->ID.',';
endforeach;?>
<?php 

$args = array(
'category__and' => array( $catnumber )
, 'showposts'=> '10'
);

$my_query = new WP_Query( $args );
?>
<ul>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>  
    </li>
<?php endwhile; ?>
<ul>
<?php wp_reset_postdata(); ?>

I have an author page, i want to list post from current author's categories.

e.g. Im viewing John's page, and John did write Sport, Tech, News, Computer category

Then my code list from this(Sport, Tech, News, Computer) categories list random 10 post.

Regards

My code

<?php global $post, $wpdb;
$author_id = $post->post_author;
$categories = $wpdb->get_results("
    SELECT DISTINCT(terms.term_id) as ID, terms.name, terms.slug
    FROM $wpdb->posts as posts
    LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID
    LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id
    LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id
    WHERE 1=1 AND (
        posts.post_status = 'publish' AND
        posts.post_author = '$author_id' AND
        tax.taxonomy = 'category' )
    ORDER BY terms.name ASC
");

foreach($categories as $category) : 
$catnumber = $category->ID.',';
endforeach;?>
<?php 

$args = array(
'category__and' => array( $catnumber )
, 'showposts'=> '10'
);

$my_query = new WP_Query( $args );
?>
<ul>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>  
    </li>
<?php endwhile; ?>
<ul>
<?php wp_reset_postdata(); ?>

I have an author page, i want to list post from current author's categories.

e.g. Im viewing John's page, and John did write Sport, Tech, News, Computer category

Then my code list from this(Sport, Tech, News, Computer) categories list random 10 post.

But something going wrong,

Im viewin an author page, author written 4 category and 4 category have 25 post.But my code not listing 10 posts just listing 1 post. And i need random post list

Regards

My code

<?php global $post, $wpdb;
$author_id = $post->post_author;
$categories = $wpdb->get_results("
    SELECT DISTINCT(terms.term_id) as ID, terms.name, terms.slug
    FROM $wpdb->posts as posts
    LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID
    LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id
    LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id
    WHERE 1=1 AND (
        posts.post_status = 'publish' AND
        posts.post_author = '$author_id' AND
        tax.taxonomy = 'category' )
    ORDER BY terms.name ASC
");

foreach($categories as $category) : 
$catnumber = $category->ID.',';
endforeach;?>
<?php 

$args = array(
'category__and' => array( $catnumber )
, 'showposts'=> '10'
);

$my_query = new WP_Query( $args );
?>
<ul>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>  
    </li>
<?php endwhile; ?>
<ul>
<?php wp_reset_postdata(); ?>
Source Link
Genxer
  • 195
  • 1
  • 11

How can i list random post from multiple category?

I have an author page, i want to list post from current author's categories.

e.g. Im viewing John's page, and John did write Sport, Tech, News, Computer category

Then my code list from this(Sport, Tech, News, Computer) categories list random 10 post.

Regards

My code

<?php global $post, $wpdb;
$author_id = $post->post_author;
$categories = $wpdb->get_results("
    SELECT DISTINCT(terms.term_id) as ID, terms.name, terms.slug
    FROM $wpdb->posts as posts
    LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID
    LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id
    LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id
    WHERE 1=1 AND (
        posts.post_status = 'publish' AND
        posts.post_author = '$author_id' AND
        tax.taxonomy = 'category' )
    ORDER BY terms.name ASC
");

foreach($categories as $category) : 
$catnumber = $category->ID.',';
endforeach;?>
<?php 

$args = array(
'category__and' => array( $catnumber )
, 'showposts'=> '10'
);

$my_query = new WP_Query( $args );
?>
<ul>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>  
    </li>
<?php endwhile; ?>
<ul>
<?php wp_reset_postdata(); ?>