the recommended way is:
<?php
$query = new WP_Query('category_name=Category&posts_per_page=4');
if($query->have_posts()) : while($query->have_posts()) : $query->the_post();
if (has_post_thumbnail()) {
?>
<a href="https://wordpress.stackexchange.com/questions/162985/<?php the_permalink(" ') ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a>
<?php
}
?>
<h2><a href="https://wordpress.stackexchange.com/questions/162985/<?php the_permalink(" ') ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<?php
the_excerpt(); // or the_content(); for full post content
endwhile;endif;
?>
Related Posts:
- Transaction when using WP functions rather than vanilla SQL?
- How to get the list of WooCommerce product image of a certain category from database?
- How to make WordPress plugin check for database changes and then do something?
- Alter query on edit.php
- Has anyone tried putting PHP ActiveRecord on WordPress?
- How to auto login user again after change user_login
- How to display multiple Post meta_key/meta_values by SQL query
- How to Join two tables from separate databases within WordPress
- count number of user comments with a specific comment meta value
- Copyright info change in Theme Child PHP
- Add footer.php to WordPress child theme
- I want to remove the links from the term list returned by get_the_term_list
- WPDB: how to get the value of a field in a custom database table
- Can I run custom php on specific pages in wordpress?
- Successful or Error Message after running mysql code in functions.php
- Can I view my own wordpress php source code on my hosted web server?
- my function doesn’t return my post from today
- Enhanced WordPress Search
- register_activation_hook isn’t adding table to DB
- What SQL / WordPress queries would need a nonce?
- How to display php source code inside a post using visual editor?
- stats_get_csv (WordPress Stats) to only display top posts (not pages)
- Hide wordpress field if data is empty in post!
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Get stock by custom meta field on all Woocommerce variable products
- Transferring working local PHP site to wordpress – with database (MySQL)
- how to delete 30 day old data using PHP [closed]
- Display fields as values in array from external SQL DB
- Latest post in a specific menu
- Importing Geo data into wordpress database
- Detect session/cookie variable in wordpress to prevent access to documents
- How to save checkbox values for logged in users?
- Querying wpdb using PHP
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- Archive post by meta value + 24hours
- Genesis framework comments broken?
- $wpdb->insert() does not Insert record in a table
- Databases – Submitting data from inputs to database [closed]
- Is it best to avoid using $wpdb for security issues?
- Use $wpdb or other PHP script method to find/replace in WP database
- Correct PHP to output a single result of a Function with SQL Query
- How can I add a new row in a separate database when someone registers via WordPress?
- Fatal error: Uncaught Error: Call to undefined function get_header() [closed]
- PHP -> SQL Query with Summing
- Filter results from a serialized string to use on statistics
- wordpress site – using custom database and PHP
- Use variable in SQL statement
- using wp enqueue style to create a CSS file specifically for a page template
- Accidentally deleted php code in WordPress website [closed]
- wpdb getting avatars and author url
- mySQL queries are executed twice on wordpress website
- random reason on refresh
- Insert PHP code in Text
- Fetching review value using wpdb class
- Remove password protection from all posts
- wordpress sql posts query won’t display the latest post in a specific category
- Display latest post from WordPress Featured Category that is also in X,Y,or Z categories
- PHP code snippet to remove microdata
- WP_Query: How to get results from both meta_key options?
- Counting number of posts in multiple (sub)categories using shortcode
- Need help for some PHP code
- Database SQL query error
- WordPress SQL Prepare
- Woocommerce display orders with products from specific categories to specific admins
- Copying and pasting to WordPress “code editor” code via the front end and clipboard
- add role on WordPress in PHP on a second database
- How to preload header logo image in WordPress? like what’s the code and where do I put it?
- Fetch Data from an external MSSQL Database in a Managed WP hosting
- Run a sql (update) after 12 hours after the user login. Woocommerce users
- How to put 2 php codes in functions.php without site crashing
- Woocommerce – get daily sales meta
- Running a PHP SQL script on a wordpress page
- Collect all events in one year
- admin-ajax.php 400 bad request – whats wrong with my code?
- Inserting other fields to existing registration form in a WordPress theme
- style.min.css code issue
- Getting error in sql query
- user update profile for custom code
- Where to check in PHPmyAdmin / SQL database for subdomain
- Front end/Database connection in WP
- Plugin Modification Change Functionality For Logged User Only
- SQL Query Search page
- can’t delete a row from post_meta table
- Conditional statement within WP SQL query
- Can not manually create a database ( db, user, pass ) for a plugin
- Sum of Custom Meta written by Authour
- How to merge 2 WordPress sites?
- Blog only showing code
- How to export database correctly for local to online
- why is markup routinely placed in functions in wordpress?
- Themes with variable width or single columns? I want to display source code
- Open all external links in new window – need help with the code
- How to get the Woocoomerce subtotal value without tax in the hardcode? [closed]
- Where to put include php file?
- Can you not edit the HTML and PHP of your WordPress without paying?
- Can’t send form data to wpdb when URL has query string
- Dynamically added text at bottom of article – non searchable by PHP code
- SQL query to retrieve the number of WordPress posts with all given categories
- How to sort search result by post_title, then by post_content
- how to create twitter card without plugin in wordpress website?