AnswerBun.com

I want to get title name of post, but i didn't get by this code. Any suggestion?

WordPress Development Asked by Ankit Sain on January 6, 2022

add_shortcode('sort_featured_restaurant','sort_featured');
function sort_featured(){

 $the_query = new WP_Query( $args );

 // The Loop
 if ( $the_query->have_posts() ) {
   echo '<ul>';
   while ( $the_query->have_posts() ) {
    $the_query->the_post();
    echo '<li>' . get_the_title() . '</li>';
   }
   echo '</ul>';
  } else {
  // no posts found
 }
// Restore original Post Data
wp_reset_postdata();

 if(!$wp_query) {
        global $wp_query;
    }

 $args = array(
  'post_type' => 'food',
  'orderby'   => 'meta_value_num',
  'meta_key'  => 'listing_price',
  'order'  => 'DESC'
 );
 $query = new WP_Query( $args );

 query_posts( array_merge( $args , $wp_query->query ) );
}

One Answer

Use this code:

$args = array(
    'post_type'      => 'food',
    'orderby'        => 'meta_value_num',
    'meta_key'       => 'listing_price',
    'order'          => 'DESC',
    'posts_per_page' => $count,
    'paged'          => $paged,
);

$loop = new WP_Query( $args );
if ( $loop->have_posts() ):
    while ( $loop->have_posts() ) : 
        $loop->the_post();
        echo get_the_title();
        echo get_the_content();
    endwhile;
endif;

Answered by Review Rights on January 6, 2022

Add your own answers!

Related Questions

Adding microdata using Structured Data Markup Helper HTML

1  Asked on December 6, 2020 by desislava-angelova

     

Server timeout error on every weekend

0  Asked on December 6, 2020 by dhaval-joshi

 

How do I make a shortcode to display the shop name on Dokan?

1  Asked on December 5, 2020 by sean-taylor

 

Excess dependencies

1  Asked on December 5, 2020 by lovor

   

A conditional button

1  Asked on December 3, 2020 by aashish-tripathi

       

Visual editor not saving data

0  Asked on December 2, 2020 by jasierok

     

WordPress Register Form

0  Asked on November 30, 2020

   

New post status for custom post type

3  Asked on November 30, 2020 by dclawson

   

Showing related post for custom taxonomy

1  Asked on November 28, 2020 by luca

 

How to hide “Change role to” dropdown on Users admin menu

0  Asked on November 27, 2020 by rijal-islami

     

Colliding custom permalink rules

0  Asked on November 26, 2020 by laurent

   

how to redirect the link to a category in the website

1  Asked on November 26, 2020 by jeline

 

Custom payment gateway issue

1  Asked on November 26, 2020 by klevis-miho

 

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir