Questions tagged [posts]

Posts are the core of WordPress. They store content, are categorized, and are expansible with meta. Posts are grouped by post type, and within their post type by taxonomy (though a taxonomy can span more than one post type).

Filter by
Sorted by
Tagged with
182 votes
5 answers
525k views

Get WordPress post content by post id

How can I get WordPress post content by post id?
m3tsys's user avatar
  • 2,047
82 votes
14 answers
150k views

Remove slug from custom post type post URLs

It seems that all web resources based on the subject of removing a custom post type slug ie yourdomain.com/CPT-SLUG/post-name are now very outdated solutions often referencing pre WP version 3.5 ...
Ben Racicot's user avatar
  • 1,396
67 votes
1 answer
77k views

Get page ID of page that is set as the posts page

In WordPress settings you can set a page as the Posts Page. This can be found: WP-Admin->Settings->Reading Settings->Front page displays How do I retrieve the page ID that is set in this ...
Scott's user avatar
  • 12.2k
46 votes
4 answers
233k views

How to limit the number of posts that WP_Query gets?

I have been researching on Google and WPSE and the only thing I see repeatedly is to use showposts, that is deprecated. I am familiar with WP_Query, and I thought that if I set posts_per_page to my ...
EliasNS's user avatar
  • 702
42 votes
4 answers
180k views

Get Posts Under Custom Taxonomy

I am not getting the posts under custom taxonomy(fabric_building_types). I am getting cat_id and cat->name also but not able to get the posts. $args = array( 'type' => '...
Parth Kumar's user avatar
38 votes
11 answers
33k views

Stop Wordpress Wrapping Images In A "P" Tag

I have searched high and low for a simple solution to this, but to no avail. Wordpress keeps on wrapping my images in p tags and because of the eccentric nature of the layout for a site I am working ...
Dwayne Charrington's user avatar
35 votes
8 answers
70k views

Stop WordPress automatically adding <br> tags to post content

Is there a way to stop WordPress from automatically inserting <br> tags when adding returns in the WordPress text editor. I would like for it to behave more like a code editor where I can ...
mvaneijgen's user avatar
34 votes
11 answers
94k views

GET the excerpt by ID

Why is it that one cannot get the excerpt by ID like with the title and most other elements. eg. get_the_excerpt(ID). I know how to use it with the $post->post_excerpt function but that does not ...
Robin I Knight's user avatar
34 votes
1 answer
13k views

When is the 'post_content_filtered' column in database cleared by WordPress?

Some WordPress plugins (although very few) use the post_content_filtered column in database to save some data related to a post. For example, Markdown on Save stores the markdown version of a post ...
its_me's user avatar
  • 4,491
33 votes
6 answers
15k views

Turn a URL into an Attachment / Post ID

Is there any way I can take a URL of an image and find the attachment or post id of that image in the database? Here is the situation: I'm in a loop going over all the 'img' tags that are surrounded ...
Ankur's user avatar
  • 433
31 votes
5 answers
80k views

How to update custom fields using the wp_insert_post() function?

The WordPress function is used for submitting data programatically. Standard fields to submit to incude the content, excerpt, title, date and many more. What there is no documentation for is how to ...
Robin I Knight's user avatar
30 votes
3 answers
114k views

Hook for post and page load

I need to run a function when a particular post or page is loaded. Is there any hook that lets me check whether a post is being displayed during page load ?
Poulomi Nag's user avatar
29 votes
5 answers
30k views

How to add an admin notice upon post save/update

I have a post type the uses post_save to take the address from the post-meta and retrieve the lat/lng coordinates from the Google API. I need a way of notifying the user if there was an issue with ...
Jason's user avatar
  • 403
28 votes
6 answers
81k views

Determine if page is the Posts Page

On the Reading Settings page you can set a "Front Page" and a "Posts Page". You can check whether the current page is_front_page(); Is there a similar function for the "Posts Page". I have noticed ...
mike's user avatar
  • 335
28 votes
3 answers
69k views

How to get 'post_content' without stripping <p> tags?

I'm trying to retrieve the post content of a specific post: $post = get_post(/* id */); $content = $post->post_content; However, this retrieves the content with no line-breaks and omits all <p&...
Lisandro Vaccaro's user avatar
26 votes
4 answers
35k views

Manually set global $post vars with an ID, in order to use template tags

I have a function retrieving ID's of posts by very specific means. I need to be able to set the global $post in order to use functions like the_content(), which does not allow an ID as a parameter. ...
Mild Fuzz's user avatar
  • 4,170
23 votes
5 answers
83k views

Get the Current Page Number

In a situation where one has 20 posts per page. I would like to get the current page number in order to make some nice page links at the bottom. How do you get the current page. I tried this <?...
Robin I Knight's user avatar
23 votes
6 answers
57k views

Print Current Post Index number within Loop

I'm working on WordPress where I have following code to get posts within loop. <?php $posts = $woo_options['woo_latest_entries']; query_posts('post_type=...
MANnDAaR's user avatar
  • 363
23 votes
1 answer
2k views

Should we trust the post globals?

@toscho left a comment to this answer which had me thinking again. How much trust should we have in the global scope, specially regarding the post globals like $post? So what? The global variable ...
Pieter Goosen's user avatar
22 votes
4 answers
12k views

Show a different number of posts per page depending on context (e.g., homepage, search, archive)

In the Reading Settings, there is place to set the number of posts shown that affects the number of posts shown in all contexts. I'd like to show instead a certain number of posts on the homepage, and ...
Doug's user avatar
  • 1,039
22 votes
1 answer
3k views

Optimize post insert and delete for bulk operations?

Not much noticeable when working with individual posts, but when you create or delete multiple thousands in bulk and by code - process is quite slow. Are there any good tweaks to apply and corners to ...
Rarst's user avatar
  • 99.3k
21 votes
3 answers
11k views

WP_Query Pagination on single-custom.php

What I am looking to do: Setup WP_Query pagination in a single-custom-post-type.php template file What I have done 1) Created a post type called "authors". Each post within that post type is an ...
Shane's user avatar
  • 339
20 votes
3 answers
67k views

How do you add thumbnail support for custom post types?

the thumbnail support is working for post, but I have another post type called product and it is not working for this. I am trying: add_theme_support( 'post-thumbnails', array( 'post', 'product' ) ); ...
Andrew Welch's user avatar
  • 1,039
20 votes
3 answers
43k views

Change Posts per page count

In the wordpress settings => Reading => Blog pages show at most [input field] posts I have it set to 3 posts at the moment. On my index, date archives, tag archives, category archives, search ...
JasonDavis's user avatar
  • 1,670
20 votes
2 answers
15k views

Restrict custom post type to only site administrator role

How can I remove this custom post type from being shown in the dashboard for non admin users? /* Add Websites Custom Post Type */ add_action( 'init', 'create_website_type' ); function ...
urok93's user avatar
  • 3,994
17 votes
4 answers
54k views

How to display related posts from same category?

Is it possible to display related posts from same category as the current post?
BBee's user avatar
  • 329
17 votes
3 answers
28k views

Add extra parameters after permalink?

How can I add extra parameters after a permalink, specifically if I'm using a custom post type? For example, let's say http://mysite/album/record-name was the permalink. How can I make http://mysite/...
relm's user avatar
  • 333
17 votes
5 answers
4k views

How to mark every 3rd post

I'm working on a WordPress site for my band and I'd like to mark every 3rd post on our blog page to have a special class applied to it, anybody have any pointers on how to achieve this? Any help is ...
Zoran M's user avatar
  • 173
17 votes
5 answers
39k views

Can posts have parents?

Are posts supposed to have parents? If so, what would that mean for a post to have a parent? Also, if there are some constraints to posts having parents, then where is that enforced? Not in the DB as ...
Alexander Bird's user avatar
17 votes
1 answer
695 views

Keep featured content post in homepage with original order

I'm searching how to keep the featured post in my blog homepage without excluding it from query post. My blog uses the Twenty Fourteen theme. I found this solution. Open the featured-content.php ...
Naziman Azlye's user avatar
16 votes
2 answers
2k views

Is there a action hook for the "Empty Trash" button?

I would like to run a function when the user clicks the "Empty Trash" button for posts. Something like: add_action('empty_trash','myFunction'); function myFunction(){ // My code }
Sebas's user avatar
  • 173
16 votes
5 answers
9k views

How to end the excerpt with a sentence rather than a word?

Here is the excerpt of the post on my home page. I want to end the excerpt with a sentence. In this case it is ' opportunities. '. I know how to modify the length but it won't do what i want. Here is ...
Mohit's user avatar
  • 319
15 votes
3 answers
76k views

How to get posts published between a date and today?

Is it a way to get posts published between a date and today with query_posts() ? Example : All posts published since 2012-04-01 Thanks EDIT : How to add the filter date on this Query Posts ? ...
Steffi's user avatar
  • 745
15 votes
4 answers
261 views

How do I check if I linked to a post before I delete it?

If I want to "safely" delete a post. I want to make sure that no link exists (within my blog) to "to-be-deleted" post. How do I do that?
user3047's user avatar
  • 536
14 votes
2 answers
36k views

How to check if post meta key exists or not in wordpress database

I want to check if post meta key exists or not, out side of the loop. Is there any WordPress function to check if post meta key exist or not in WordPress database. I have to check this outside the ...
Rabin shrestha's user avatar
14 votes
2 answers
37k views

How to detect single.php (but not single-portfolio.php)?

When I'm using is_single(); in my <head> section to add some style to website navigation it executes correctly on blog posts but it also executes on single "portfolio" post type posts (so single-...
Paul's user avatar
  • 2,140
14 votes
5 answers
10k views

How to change the case of all post titles to "Title Case"

I am helping my father with his WordPress website. It has over 1,700 posts with TITLES IN UPPERCASE. We'd like to change these to "Title Case" in the database (possibly using this PHP script). The ...
BaronGrivet's user avatar
14 votes
5 answers
52k views

How to retrieve text only from wp_content() not from wp_excerpt()?

I'm currently developing a website with WordPress 3.5 and I need to retrieve Post Text (Only text, not include images) at Archive Page. I can retrieve it with wp_excerpt() method without any problems. ...
Thiha Maung's user avatar
14 votes
2 answers
34k views

Adding Page Attributes Metabox and Page Templates to the Posts Edit Page?

(Moderators note: Title was originally "How can I add the "Page Attributes" and/or "Page Attributes > Template" selector to POSTS editor") WP currently only allows the assignment of a "template" to ...
Scott B's user avatar
  • 5,666
14 votes
2 answers
412 views

Appending content with <!--nextpage--> broken in 4.4

Update 2016-01-21 All current testing on my end is being done on fresh installs of 4.4.1 with the following settings: Plain permalinks Twentysixteen Theme No plugins activated If the post only has 1 ...
Milamber's user avatar
  • 143
13 votes
3 answers
112k views

How to show related posts by category

In my gallery site i want to show other pictures under the current picture (in single post). I seen more codes but it i asks to specify the category, but i dont want want specify the category manually ...
Felix's user avatar
  • 333
13 votes
3 answers
9k views

Apply the_title() filter in post & page title, but not in menu title

I use the following code to change the title of WordPress posts and pages. But it changes nav menu item titles too, which I want to avoid. I want to change the title of posts and pages in: home page, ...
Ranuka's user avatar
  • 1,782
13 votes
1 answer
6k views

Change permalinks for posts but not for custom post types

Currently my permalink structure for posts is domain.com/post-title I'm using a static front page and a "blog" page for posts. I'd like to to change the permalink structure for posts, tags and ...
user2019515's user avatar
13 votes
2 answers
6k views

ZIP up all images displayed in a [gallery] and offer as download link

I would like to offer my visitors the option to download the entire photo gallery (displayed on dedicated [gallery] pages) as a ZIP file displayed at the bottom of each gallery page. - The full-sized ...
Paul Thomson's user avatar
13 votes
3 answers
11k views

Keyboard shortcut for updating a page or post?

What is the keyboard shortcut key for updating a page or post? It could save me a lot of time as rolling down a page draft is time consuming.
Paul Felt's user avatar
  • 131
12 votes
2 answers
27k views

How to remove a column from the Posts page

In a previous question I asked how to add a column to the Posts page in the Administration section, and got a working answer. But now I need to know how to delete an existing column (e.g. the Date ...
Justin Long's user avatar
12 votes
2 answers
25k views

Rewriting post slug before post save

I need to retrieve an ACF field within the post, and change the slug(permalink) of the post before saving it to database. What is the approach to achieve that? I need the slug to be changed every ...
Vit Kos's user avatar
  • 223
12 votes
2 answers
23k views

Get the ID of the latest post

Been all over looking for the best way to do this. I want to get the ID of the latest post of a certain post_type. How can I do this in the cheapest way possible (by cheapest I mean using the least ...
Niels's user avatar
  • 524
12 votes
2 answers
49k views

Submit post and upload image from front-end

I am trying to do something similar to the above question. I am trying to make users post and upload images from front-end. I have already done the post form and its working. I just followed and ...
Govnah Antwi-Boasiako's user avatar
12 votes
1 answer
30k views

Access post from post id in URL

I'm doing unit tests for my plugin, and in my unit test, I check some basic things such as posting a custom post type. My script can create new post, and I can retrieve the ID of the posted item (I'm ...
Alexandre Germain's user avatar

1
2 3 4 5
120