I’m not sure how much of a help this will be, but this is a (probably overly convoluted) snippet of code I wrote a few years ago for a shortcode to display posts by category. If nothing else it may at least put you on the right track.
$featured_posts = get_posts(
array(
'category' => $atts['cat'],
'posts_per_page' => -1
)
);
Related Posts:
- Check if a menu is empty?
- WordPress Template Engine?
- How to get the post count for the last x days filtering by categories
- Display only text to WordPress loop without loosing the text formatting
- How to create shortcodes that pull custom field data from general settings
- Where exactly do I write define( ‘WP_DEBUG’, true ) in wp-config file
- How to display related posts from parent category
- Making a follow button, Ajax not talking to php
- get understrap pagination to work with custom query
- Replace existing content from specific WooCommerce admin orders list column
- How do I get images (with a thumbnail preview) to show in search results?
- How do I translate this string – PHP syntax question
- Warning when using
- How to break down importing of feeds
- PHPCS: Strings should have translatable content
- WordPress shows registration link for non logged users
- How to get woocommerce cart content without an action?
- php syntax – how to concatenate properly – echo bloginfo(‘stylesheet_directory)
- How can I resolve the php notice “Constant EMPTY_TRASH_DAYS already defined”
- Use wp_get_recent_posts with search term
- multiple if statements [closed]
- Escape post image attachments added to template
- Choose To Display Post Views With An Options Panel
- Prevent Data Resubmission On Page refresh
- Bridging TinyMCE js and WordPress PHP?
- Echo URL of large version of Featured Image
- Get_avatar filter?
- Remove price from Woocommerce variable product dropdown menu
- WP dynamic featured image – Can’t get second featured image url
- Getting trackpacks/pingbacks for a post via wordpress?
- Why is my cookie not unsetting upon logout? [closed]
- Loop through categories and display posts title under each dropdown
- How to hide products that do not have an image from a slider carousel for an ecommerce webpage?
- How to remove role=”navigation” from all nav elements?
- how to query a post based on previous page post ID
- How to use $_GET function WordPress backend
- How to set variable, pass it to a partial file and remove it after?
- is there a benefit in using a constant over get_stylesheet_directory_uri?
- wp_dropdown_pages auto submit
- How to loop through all the attached images in a post, and get their url one by one
- Use Tags to initiate Search
- Show About and Contact Us page when they’re clicked in the top menu.
- Displaying posts based on category
- How to send form data from WordPress (Meta Box) to an OData service?
- Noindex Posts From Certain Authors In WordPress
- Pass Variables or Variable Place-Holder from Editor to PHP
- Issue with custom loop in Archive page
- WooCommerce pages looks unstyled
- class ‘wphpc_PAnD’ not found
- Accessing values from ACF sub field (flexible content area) in PHP
- Get the_content surrounded by instead of
- WordPress forms submissions and PHP files
- Display an image based on field value
- Loading Posts & Category with Ajax
- WordPress call post-ID in jquery
- Enqueueing a code block from an options framework
- List all anchor links on a page
- Assign Custom classes to every Excerpt
- Don’t display a sidebar widget when on a specific page
- Auto create Nextgen Gallery on post creation [closed]
- Hide media for non logged in users
- display the months of a specific category
- How to display 8 posts in four columns and 2 rows on a carousel slide?
- How to run php code only for a specific widget on a page and not all widgets on that page?
- excep tonly one css, don’t load any css
- is_front_page is not working in my functions.php
- Is it possible to update the dataset using update_post_meta
- Add Link to PHP message
- Hide payment method based on user role AND minimum cart value
- WooCommerce function not working correctly after moving from the functions.php into a class
- How to check if plugin update process completed in wordpress?
- Filter for product subcategory listing page load
- Conditional Banners
- Reduce Stock Based on Custom Variation Field Rather than Attribute (Working Script)
- Install functionality for push notifications but WP-Theme has oddly-named, hidden source files [closed]
- how to use auth_redirect() redirect visitor to login page if they are not login when they click account and order page?
- CRON job to update wp_usermeta value each day or week based on server time
- Send Notification to all users that followed some author
- Search function not working
- loop to return tags in woocommerce in alphabetical order?
- how to edit open graph meta description programmatically and in which file
- Embedded pages by ID are not respecting Private and Draft status
- What image is this pulling?
- How to use foreach and if statement within array of arrays?
- For each 3 posts, show a different post type
- Include a custom field in mysql query
- Adding a sidebar to wp-login.php
- Adding category in wordpress – custom
- How to set a cookie based on a page Get variable?
- Editing the contents of just one div on a page from wordpress
- Postmeta not saving
- How to change the menu color
- Display latest 5 posts on homepage
- Display Current Time using shortcode
- SQL – How to echo out inside of where statement
- How to create different templates for woocommerce single-product.php?
- How can I update a value of a field depending on outside source?
- Restricting access to a file for everyone except logged in users
- WordPress Block Editor Gutenberg running code inside ! is_admin()
- Tags being Inserted in html from plugin PHP not passing through the_content