But for some reason my posts get overridden instead of displaying new
data.
The problem is here: $announcements->query('showposts=1&cat=$category_id');
You are trying to use a variable inside a single quote string. Variables do not expand inside single quotes so instead of asking for cat=1
, or cat=2
, you are literally asking for cat=$category_id
— just like that, spelled out in full.
What you need instead are double quotes: $announcements->query("showposts=1&cat=$category_id");
. Variables do expand in double quote.
Or better, an array– far more readable and maintainable:
$args = array(
'posts_per_page' => 1,
'cat' => $category_id,
);
Note: showposts
is deprecated. Use posts_per_page
.
Related Posts:
- Post/Page Preview Template
- How to get Images included in Post
- My ‘post attributes’ is missing from my WordPress install
- posts page – different lengths of excerpt
- Forcing oembeds to top of post
- Accessing $post variable from template part
- how to show all post in my page-grid.php template page
- Use template of parent category for single post sub-categories
- loop not displaying posts on custom template page
- Including text at the end of every post
- custom single.php not working
- Adding variable for post title so post template can include auto-generated link to view on external website.com/{post title}
- How to display different single post template based on author?
- How only display all post related to category
- Is it possible to have two different previews of a post (ie. two templates for one post)?
- Display page content AFTER a loop of posts
- Different template for posts of all subcategories of category
- Custom Post Templates
- Single post as homepage?
- Templating of a specific post ID
- Category Template: Need to display different content on first page of archives
- Change post_date to post_modified date on post template?
- What part of template to edit to remove category name from the top of posts?
- How can I pass the ID of a post to a page template by clicking a url?
- Using custom post template
- What is the filter or hook to add admin controls to posts on the front end?
- Setting posts_per_page for taxonomy term template
- Switch to page template when using post permalink
- Genesis + Ajax + Jquery | Failling to call action
- Get Page ID of blog homepage
- Send post id through ajax and get the post content back
- custom post template file not shown, instead all the time 404.php
- How to create new post content templates for my users?
- How to create a template for Pages?
- How do I stop the loop from repeating in my category template?
- posts not showing on index.php
- Hide a specific post from a page template
- Tell WP to use a specific template file in posts
- How to make different custom post layouts?
- Why won’t pagination work?
- Is it possible to give the user the chance to select between two single template files to use in a post?
- Create a custom posts page
- how to set social icons to product / post template (Auros theme)? [closed]
- How to identify and hide/remove an element from a WordPress page [closed]
- wordpress posts template remove default template from menu
- Force a specific template as default
- showing posts of an specific category in admin custom menu with style of admin posts section
- Give posts a particular template based on the assigned category
- Display a post via template
- Single post full screen template not inheriting WordPress role permission
- How to set a certain Custom Template to a Single Blog Post
- List all native posts in template page?
- Sidebar on single.php not showing up
- How to Featured content with images in home page?
- How do I disable the “by author” hyperlink on posts?
- Trying to query all posts in category 4
- Output Buffer Issue with Single Post View
- add_rewrite_rule and template redirect not working
- Prevent 404 of Author pages without posts
- Custom post type and taxonomy page templates
- How to save template data into wp_post table (post_content column)
- How to allow WordPress to recognize a custom URL segment after a product URL and use a custom template?
- How do I change the template specifically for single posts?
- Related post not showing table of content
- Post not using taxonomy template
- Why does my “Add New Post” page have an old post in it?
- Customizing a new page used for blog posts with Avada theme
- Single Sidebar; multiple templates! How?
- How to Display Most View Post in the template file?
- Use special template for the first post in the loop
- Is it possible to query a category with specified posts?
- Custom post type template not called
- Page 2 has no posts?
- single- and archive- templates not being applied to custom post types, not even after flushing permalinks
- How to change post template via url?
- how to remove entry meta from wordpress archive category and change its display
- My blog “page” used to show a list of posts, but now it’s just showing the page content?
- Custom template for different post types
- Adding The Post Template Dropdown to WP-Admin
- Posts page template: How can I edit the markup for this?
- How to arrange different post categories in template
- How can I change the look of a post as is displayed
- Which hooks are essential for post templates?
- Display the first post’s comments of category in comments.php template
- 1 post, 2 templates
- how to style an individual page in a category [duplicate]
- How to display a certain template element only for posts published within certain time range?
- Redirecting posts in WordPress to a specific page
- Creating / Editing a post from within site template
- custom post type single page template not working
- WordPress “Posts Page” isn’t showing template dropdown
- How do I create a template page to show 3 blog posts?
- How to add a new page that will function as a separate blog/news article page
- excerpt in template for specific page
- Tag page that displays specific posts
- Is there a block to print post link standalone in a block theme?
- How can I locate the single buddypress forum post template? [closed]
- How can I replace the text at the top of a custom column into a icon?
- count the total number of comments the user has received for his published posts
- How to convert attachment pages to Posts?