logo
down
shadow

Wordpress get most popular posts in current post category


Wordpress get most popular posts in current post category

By : user2185241
Date : November 21 2020, 04:01 AM
fixed the issue. Will look into that further I'm looking to get the top 3 most popular posts on the bottom of all my posts. Which I've achieved. But I really need to display the top 3 most popular within the current post's main category. , to match the category try this:
code :
$args = array(
     'posts_per_page' => '3',
     'meta_key'=>'popular_posts', 
     'orderby'=>'meta_value_num', 
     'order'=>'DESC',
     'tax_query' => array(
                        array(
                            'taxonomy' => 'category',
                            'field' => 'id',
                            'terms' => array ( 60 ) //you can add more comma separated category ids here
                        )
                    )
                );
$popular = new WP_Query( $args );
if (  $popular->have_posts() ) :
     while ( $popular->have_posts() ) : $popular->the_post(); 
          echo '<div class="entry-content">';
          echo '<h2 class="entry-title main_title">'.get_the_title().'</h2>';
          the_content();
          echo '</div><!-- .entry-content -->';
     endwhile;
endif; 
wp_reset_query();


Share : facebook icon twitter icon
WordPress - Getting Posts by Custom Post Type and Category, with each category automatically encased in a DIV

WordPress - Getting Posts by Custom Post Type and Category, with each category automatically encased in a DIV


By : Roycer Israel Cordov
Date : March 29 2020, 07:55 AM
should help you out i did this it gets all taxonomies but it could easily be modified to active what your trying
code :
// for a given post type, return all
$post_type = 'shows';
$tax = 'show-topic';
$tax_terms = get_terms($tax, array('orderby' => 'id', 'order' => 'ASC', 'exclude' => '135, 49, 25, 24, 54'));
if ($tax_terms) {
    foreach ($tax_terms as $tax_term) {
        $args = array(
            'post_type' => $post_type,
            "$tax" => $tax_term->slug,
            'post_status' => 'publish',
            'posts_per_page' => - 1,
            'orderby' => 'title',
            'order' => 'ASC',
            'caller_get_posts' => 1
            ); // END $args
        $my_query = null;
        $my_query = new WP_Query($args);
        if ($my_query->have_posts()) {
            echo '<h3>' . $tax_term->name . '</h3>';
            while ($my_query->have_posts()) : $my_query->the_post();
            ?>
          <div class="post row" id="post-<?php the_ID(); ?>">
                    <div class="thumb-box three column">
                        <?php
            $src = wp_get_attachment_image_src(get_post_thumbnail_id());
            if (has_post_thumbnail()) {
                the_post_thumbnail();
            } else {
                if (get_post_meta($post->ID, "thumbnail", true)):
                    ?>
                                <a href="<?php the_permalink() ?>" rel="bookmark"><img src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" alt="<?php the_title(); ?>" /></a>
                            <?php else: ?>
                                <a href="<?php the_permalink() ?>" rel="bookmark"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/insp-tv-small.png" alt="<?php the_title(); ?>" /></a>
                            <?php endif;
            }
            ?>
                    </div>
                    <div class="post-content nine columns">
                        <h4 class="posttitle archiveposttitle">
                            <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e('Permanent Link to', 'buddypress') ?> <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
                        </h4>
                        <div class="entry">
                            <?php the_excerpt(); ?>
                        </div>
                    </div>
                </div>
          <?php
            endwhile;
        } // END if have_posts loop
        wp_reset_query();
    } // END foreach $tax_terms
} // END if $tax_terms

?>
How to display popular post by view in current category?

How to display popular post by view in current category?


By : Ajay Singh Rajpoot
Date : March 29 2020, 07:55 AM
like below fixes the issue The question title is a bit confusing. there is a way of getting the "popular" posts by comment count but that "by view" in the title of your question suggest you are looking for a different way to go about it?
.
code :
<?php
    $category = get_category( get_query_var( 'cat' ) );
    $curCatId = $category->cat_ID;

    $args = array(
        'numberposts'   => 10,
        'cat'           => $curCatId,
        'meta_key'      => 'views',
        'orderby'       => 'meta_value_num',
        'order'         => 'DESC'
    );
    $popPosts = get_posts( $args );


    echo '<ul>';
    foreach ( $popPosts as $popPost ) {
        setup_postdata( $popPost );

        echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';

    }
    echo '</ul>';   

wp_reset_postdata();
?>
<?php
    $category = get_category( get_query_var( 'cat' ) );
    $curCatId = $category->cat_ID;

    $args = array(
        'numberposts'   => 10,
        'cat'           => $curCatId,
        'orderby'       => 'comment_count'
    );
    $popPosts = get_posts( $args );

    echo '<ul>';
    foreach ( $popPosts as $popPost ) {
        setup_postdata( $popPost );

        echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';

    }
    echo '</ul>';   

wp_reset_postdata();
?>
Wordpress get_posts() returns all posts from Custom Post Type instead returning only selected category posts

Wordpress get_posts() returns all posts from Custom Post Type instead returning only selected category posts


By : zaid omari
Date : March 29 2020, 07:55 AM
should help you out I use widget plugin Getting the random post & URL via ajax. fischi for help to rewrite functions. Problem is that function returns all posts from CPT, so category select doesn't work. , So i add this
code :
if ( isset( $_POST['usecategory'] ) && intval( $_POST['usecategory'] ) != 0 ) {
  $args['tax_query'] = array(
    array(
      'taxonomy' => 'portfolio-category',
      'terms'    => intval( $_POST['usecategory'] )
    )
  );

}
WordPress popular posts how to show posts like category?

WordPress popular posts how to show posts like category?


By : Nathan M Banda
Date : March 29 2020, 07:55 AM
How can I show all posts of a custom post type from current single post category in WordPress?

How can I show all posts of a custom post type from current single post category in WordPress?


By : Patrickh80
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have a custom post type and it have many categories. When I open a single post of this custom post type post, then at the bottom of this custom single post, I want to show 8 posts title, image etc from this single post category. , Add this code in single.php of your theme.
code :
$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 8, 'post__not_in' => array($post->ID) ) );
if( $related ) foreach( $related as $post ) {
setup_postdata($post); ?>
 <ul> 
        <li>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
            <?php the_content('Read the rest of this entry &raquo;'); ?>
			<?php the_post_thumbnail( 'thumbnail' ); ?> 
        </li>
    </ul>   
<?php }
wp_reset_postdata(); ?>
Related Posts Related Posts :
  • Laravel : How to retrieve data from inside an nested array
  • Codeigniter search with comma-separated values
  • upload file on laravel 5.7
  • Wordpress - How to display 10 users only?
  • Display the results in the HTML
  • PHP - mysqli_fetch_assoc, 2 results then into an array
  • mysqli update database receiving email and password reset token
  • PHP mailer not creating new lines
  • IF / OR statement causes Call to undefined function() error. Why?
  • How to read Protocol Buffers delimited I/O functions
  • Creating a link from Google Chart timeline item
  • Rewrite PHP variables from URL with .htaccess
  • Undesired output for php array creation
  • Symfony 4 - custom authentication FosUserBundle
  • laravel: cant push object property to array
  • When sharing on facebook, showing angular brackets in title and decription
  • Undefined function: 7 ERROR: operator does not exist: public.ltree public.< public.ltree[]
  • Generate a CSV in php from Array or Object
  • LibreOffice convert PDF to Word as textbox instead normal document
  • php laravel swift email sending problems
  • Reload PHP file in command line PHP-CLI
  • how do I fetch a certain part out of an database?
  • CodeIgniter URL Route with ID and title
  • Add a header to each column
  • How can I loop stdClass in PHP?
  • Four arrays in for each loop
  • bootstrap 4 cards with php foreach loop
  • Codeigniter return not found on the server
  • PHP Codeigniter Do Upload Function Does Not Work
  • Implement REST API Symfony 3
  • how to add show data button in Yajrabox
  • My WampServer doesnt have apache setting in tray icon
  • Translate checkout fields validation error notices in Woocommerce
  • Embedding nested form type fields in empty symfony form
  • PHP Laravel orderby not working if using `count`
  • Laravel 5.7 my model from my parameter return's empty when i dump it
  • How to pass input value as array instead of passing only one value where array_walk is used in PHP?
  • Replace illegal charactes in a text by underscore in PHP
  • PHP / JSON - Return large string result in error
  • Yii2 DI container: registering same class twice, but with different constructor parameters
  • Creating Subdirectories with a for loop
  • Replace linebreak in specific piece of text in file
  • Update database that has same key with using a new different values
  • Problems with Curl in Discord Oauth2
  • How to remove all lines in file till a specific word occures PHP
  • How to use Join in Codeigniter for update Query
  • PHP DOMDocument: may a text node be reused?
  • How to read Armenian texts from Laravel MSSQL database
  • How to view image and pdf files preview in yii2 kartik multiple file upload in update form
  • Which one is best and faster method ?(making drop down method)
  • Using preg_match to get content between tags
  • Laravel 5.7 Eloquent
  • How to combine array inside foreach loop
  • Wordpress-Stripe Integration: Fatal error: Uncaught Error: Class 'Stripe' not found
  • Redirect user to original url from age verification
  • How to update only one input in Laravel form?
  • How to add language translation in JSON file in prestashop
  • Interface 'Monolog\ResettableInterface' not found when running a new project
  • Adding strings when using echo in foreach PHP
  • do-while loop only runs once
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org