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?
- Transaction when using WP functions rather than vanilla SQL?
- $wpdb->get_results(…) returns empty array despite correct query
- 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
- Would manually deleting the dumping data fix a “#1062 – Duplicate entry ‘1’ for key ‘PRIMARY'” phpMyAdmin error?
- 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?
- Database “Migration” for Plugins?
- 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
- 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?
- Hide wordpress field if data is empty in post!
- How to get the POST TITLE using the POST ID?
- 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
- Cause of Blank Lines Being Added to WP FIles?
- 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]
- Insert custom PHP head above in WP pages
- Log in / Log Out Custom Button
- How to do a code in php and have text before it? [closed]
- PHP nested If statement syntax
- Display Data in Table from External Database in WP using Shortcodes
- Is it best to avoid using $wpdb for security issues?
- How to Configure Events List in WordPress to Disappear Event Once Date is Past
- dynamic page using php from sql database
- Code snippet to show current php version inside “At a Glance” box in admin
- Use $wpdb or other PHP script method to find/replace in WP database
- How to Update post_modified of all wordpress post
- 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
- Lost in trying to create user database system
- Pull MySQL data from multiple tables and merge into 1 PHP array
- Filter results from a serialized string to use on statistics
- wordpress site – using custom database and PHP
- Searching Posts Programmatically in a WordPress Plugin
- Use variable in SQL statement
- using wp enqueue style to create a CSS file specifically for a page template
- Why my query does not run with prepare
- Accidentally deleted php code in WordPress website [closed]
- wpdb getting avatars and author url
- See output of a sql query while plugin installation in wordpress
- Blog only showing code
- Display pages from specific page template
- Querying multiple meta_keys in WordPress SQL query
- 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?
- Search results always returns “No results” no matter what
- Can’t send form data to wpdb when URL has query string
- Dynamically added text at bottom of article – non searchable by PHP code
- Retrieve data from external database and insert back in
- 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
- Where is WooCommerce order shipping methods stored
- How to properly prepare a column name if passed to a stored procedure?