Primary issue with your function is “get_template_part” internally use global $post variable to display the post fields. However, your $post variable is filled for this function only. I would suggest to read this handy article Displaying Posts Using a Custom Select Query
Now, specifically in your case
function lugaresincreibles_most_commented() {
global $wpdb, $post; // make $post a global variable
$pop = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}posts WHERE post_type="post" AND post_status="publish" ORDER BY comment_count DESC LIMIT 3");
foreach($pop as $post) :
setup_postdata( $post ); // set the post data.
get_template_part( 'content', 'featured' );
endforeach;
wp_reset_postdata();
}
Related Posts:
- Wpdb get->results to out the the month from the db
- How to return number of found rows from SELECT query
- $wpdb->delete column values IN ARRAY()?
- WPDB: how to get the value of a field in a custom database table
- $wpdb->flush(); breaks the loop
- Any possible way to make $wpdb->get_results() return anything else than array?
- database interactions using OOP
- Trying to establish connection to External Database
- Getting id of poll from WP database
- How to insert a single row to WP database table?
- $wpdb->update with multiple parameters gives error
- Update results, Before deleting the related category [closed]
- How WordPress reacts to a lack of memory of the server [closed]
- How to retrieve the data from the sever and displaying it in a page?
- I can’t update my data through $wpdb
- wpdb Cannot Update column in Database
- Delete database record using plugin from admin panel
- WPDB – Read and write value from / to database
- Add row to custom database Table and delete all rows older than 1 day
- select a single val though a table in wordpress
- Add posts to custom table in database instead of wp_posts
- Using wpdb to connect to a different database is not working
- How to grab data from input and store it into custom table in database?
- Accessing external database: ERR_INCOMPLETE_CHUNKED_ENCODING
- How to fetch results from database
- Querying multiple meta_keys in WordPress SQL query
- MySQL database migration to WordPress
- Fetching wpdb data from a php file seems to break?
- Insert into db with foreach problem
- How to get data (not value or name) from radio options to POST to database
- Putting form result in my database
- How to export/import theme customizer settings?
- WP API V2 returning Invalid User ID
- Print out WordPress user ID – two sites with same code but different output
- Looping through WP_Post Object
- Can’t use get_results() in ajax query
- Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder
- Access/update database with jQuery
- WordPress get pagination on wpdb get_results
- Show Custom Taxonomy Title
- spliting posts into two columns
- Add custom php database code above
- wp_insert_post not working
- Show MySQL errors that occur when I excute $wpdb->insert()
- how to delete 30 day old data using PHP [closed]
- Storing Array from returned database query and using the array in a new query
- Changing layout with wp_customise
- WordPress not reflecting changed of the database
- Why my filterable portfolio page work not perfectly between slug button and slug output WORDRPESS?
- Querying wpdb using PHP
- get author_name from queried post
- wpdb php get_var query to get ID for URL image doesn’t work for ID over 999
- Database query works fine outside WordPress
- Help with a $wpdb MySQL Query
- post thumbnail, conditions, else wont work
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- $wpdb returns duplicate posts
- Why in my theme I can’t see all the statics content under the posts?
- Creating Database Table vs. Adding MetaData to Post & User
- How to unlink all posts from tracking same amount of views
- Cant connect to database with php 7.3
- Problem with custom loop and wp_list_pluck [closed]
- WordPress loop is not working
- Fetching review value using wpdb class
- Problem in replacing the_content with the_excerpt()
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- MySQL Query Returns Array () In Shortcode
- Passing in MySQL prepare statement parameter separately throwing error
- Database SQL query error
- Change wordpress’ database data using ajax – how to get current user id?
- Pagination contents not changing in Front page WordPress
- add role on WordPress in PHP on a second database
- MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?
- Display all categories including sub categories under a list ul
- Retrieving and Displaying Data From a Table
- Where does php code to load data go?
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- Can I disable auto increment of WordPress Posts Database to utilize previously deleted records?
- Latest posts feed with a specific post always first
- Updating the database after parsing CSV document
- problem in using wpdb->prepare and a string placeholder
- How fix error in the WordPress loop?
- Advanced WordPress SQL Query
- Efficient way of querying for a “fallback” post?
- Issue in url update when using wordpress update query
- can’t delete a row from post_meta table
- Loop 1 user randomly
- Create a hierarchical loop at predefined markup requirements
- Order by in foreach
- How to display thumbnail if post is assigned one otherwise not
- Pagenav Not appearing on custom Template
- Remove the_content From Loop
- Adding if statement to content for homepage
- Tables not showing divs and loop/php items
- Pagination in category.php not functioning
- How to handle parent and child pages?
- How to create a loop that will display one post and stop?
- How to get the last date updated of postmeta?
- SQL – How to echo out inside of where statement
- How can I update a value of a field depending on outside source?