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:
- What is the meaning of %s, %1$s etc.? [closed]
- Include WP_Query in my own PHP file?
- $wpdb->get_results(…) returns empty array despite correct query
- How to get the list of WooCommerce product image of a certain category from database?
- Alter query on edit.php
- How to display multiple Post meta_key/meta_values by SQL query
- How to Join two tables from separate databases within WordPress
- Copyright info change in Theme Child PHP
- Add footer.php to WordPress child theme
- Would manually deleting the dumping data fix a “#1062 – Duplicate entry ‘1’ for key ‘PRIMARY'” phpMyAdmin error?
- Database “Migration” for Plugins?
- Enhanced WordPress Search
- How do i get (unique) page name?
- Automatically generate Post/Page from searched Database item?
- List of posts by day of the week
- register_activation_hook isn’t adding table to DB
- What SQL / WordPress queries would need a nonce?
- Renaming post IDs – Okay to do?
- How to generate page content from database the right way?
- How to display php source code inside a post using visual editor?
- The custom logo, site title, and description doesn’t appear at the same time
- phpMyAdmin displays error when importing database
- stats_get_csv (WordPress Stats) to only display top posts (not pages)
- Preferred Method of debugging a wordpress SQL calls?
- How to get the POST TITLE using the POST ID?
- Get stock by custom meta field on all Woocommerce variable products
- Display fields as values in array from external SQL DB
- Cause of Blank Lines Being Added to WP FIles?
- Importing Geo data into wordpress database
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- $wpdb->insert() does not Insert record in a table
- Databases – Submitting data from inputs to database [closed]
- Insert custom PHP head above in WP pages
- How to do a code in php and have text before it? [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
- Pull MySQL data from multiple tables and merge into 1 PHP array
- 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]
- 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
- quotes problem in very simple sql
- 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
- get_terms with specific id order
- 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
- Woocommerce template file outputting tags
- 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
- Running a PHP SQL script on a wordpress page
- Displaying SQL query result from user input via wpdb
- Collect all events in one year
- How do I get data from my database into my Custom Export Field
- 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
- How can I order metaboxes in my posts in WordPress?
- 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?
- Help writing out comments and replies