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
- Function wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder
- Unserialize Custom Field & Save as Multiple Rows in WordPress Database
- WordPress get last inserted user id
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- What’s wrong in my PHP code? I’m using WordPress Astra Theme and I can’t insert data into my SQL
- Using PHP Code Snippets to query a database, $dbconnection->get_results is outputting nothing
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- Database entry removed on browser refresh, Ajax PHP jQuery
- Passing in MySQL prepare statement parameter separately throwing error
- Convert a column of a table containing an Array as response in HTML
- Database SQL query error
- How to Add a cutsom slug to my custom author role
- How do I get pagination for get_posts() in WordPress or do I have to rewrite the whole code?
- WordPress SQL Prepare
- Please help! I have a problem with getting wordpress databas
- Give ID to divs inside the loop
- Change wordpress’ database data using ajax – how to get current user id?
- Error establishing a database connection (Set-up locally)
- $_POST returning empty values
- Products listing check if meta checkbox is checked
- Pagination contents not changing in Front page WordPress
- How to send custom form submissions to WordPress Database?
- add role on WordPress in PHP on a second database
- Create a new account on site B with data from the purchase of site A
- How to search order using database frontend short code WordPress
- Display articles with a different template in the home page | Solved |
- Limiting posts based on nested meta_query
- in_array not working on dev server but works on localhost
- How to Create Carousel Indicators in PHP Loop using wp_get_attachment_url function?
- How to output the taxonomies that are assigned to each custom post?
- Creating multiple tables with Plugin
- Get title of page containing post grid within the posts
- Check if current post in loop is last on current page
- update_user_meta as multiple value but with same meta key
- Submiting with problems on one of the options php wprdpress
- Preserving backslashes in post_content
- PHP Warning: mysqli_query(): after updating my websites php from 5.6 to 7.2
- MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?
- Is there anyway I can call the year once?
- Error establishing a database connection (configuration)
- Conditional formatting on data fetched from MYSQL
- when looping through custom post data not appearing
- wp_update_post gives 500 internal error
- Display all categories including sub categories under a list ul
- Confuse between forms and tables
- Responsive loop with 3 columns inside row then 2 columns
- code that I can run, or a plug in to show what sql tables something pulls information from
- Foreach Loop Of Post Types With Nested If Else If Not Completing Process
- Adding column to wpex_users
- Unable to insert two value in two different columns (WordPress database)
- Looping through dummy posts and showing them in the main index.php
- Retrieving and Displaying Data From a Table
- Where does php code to load data go?
- What is the correct way to search 3 custom fields only in WordPress?
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- why not selecting multiple rows of same standard_id using SQL query from database?
- Custom Loop.php having a loop inside a loop
- ACF – Get ID of relationship field in flexible content
- cURL needing to loop through all “next_page”
- Using custom php to connect to database blocks wp from accessing galery pictures
- Display page content in different sections – based on page break block?
- Looping through custom data in a custom table to display all items in a post
- Can I disable auto increment of WordPress Posts Database to utilize previously deleted records?
- Filtering custom posts by using checkboxes for taxonomy in an ajax loop always gives server 500 error
- Displaying SQL query result from user input via wpdb
- Latest posts feed with a specific post always first
- Show the subcategory name based on current product
- How do I create a WP endpoint that retrieves all custom post types that have a tag?
- Modify post image in full size