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).
456
questions
33
votes
6answers
11k 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 ...
17
votes
5answers
3k 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 ...
64
votes
12answers
98k 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 ...
5
votes
2answers
18k views
Execute function when post is published
I try to use this function i have created when a post is published for the first time.
function a_new_post($post){
$post_id = $post->ID;
if ( !get_post_meta( $post_id, 'firstpublish', $single ...
30
votes
5answers
70k 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 ...
23
votes
1answer
1k 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 ...
17
votes
3answers
25k 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/...
7
votes
2answers
18k views
The next_posts_link() works only with original $wp_query
I've got custom template that I want to display paged blog posts. This is the beginning of my file:
$wp_query = new WP_Query($args);
if($wp_query->have_posts()){
while($wp_query->...
8
votes
2answers
11k views
Front-End Post Submission
I am trying to add a form where users can submit post from front-end.
I am Following this tutorial:
http:// wpshout.com/wordpress-submit-posts-from-frontend/
What I am doing is adding this code to ...
6
votes
3answers
12k views
Set posts of a custom post type to be private by default?
Say I created a custom post type called 'Private Posts' ($post_type = itsme_private_posts) and want all posts under the custom post type to be set to 'Private' automatically when published i.e. by ...
3
votes
3answers
21k views
Display posts by month
I want to achieve something like this, I don't know if it is possible and what would be the best way to do it:
The way I query the posts is like this:
<div class="post">
<?php global $...
9
votes
2answers
5k views
Delete Associated Media Upon Page Deletion
Note
Use at your own risk, it is buggy and I have run across a couple instances where it would delete ALL attachments. Unsure why.
Is it possible to delete media associated with a page when that ...
2
votes
1answer
382 views
Developing a secure front end posting form
I want to add a front end posting functionality to one of my Wordpress sites. For more control and for more understanding of how this works (I am not a professional programmer) I choosed to use as a ...
161
votes
4answers
433k views
11
votes
2answers
46k 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 ...
32
votes
5answers
166k 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 ...
15
votes
3answers
8k 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 ...
15
votes
3answers
34k 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 ...
9
votes
2answers
7k views
Possible to change the URL for the regular post type without affecting the URL of other custom post types?
The Dilemma
I have a few custom post types:
Portfolio Items
Testimonials
FAQs
The URL structures for these custom post types are:
mysite.com/portfolio/name-of-custom-post
mysite.com/testimonial/...
7
votes
2answers
5k views
How To Disable (or Remove) “All Posts, Published, and Trash” in Dashboard Posts
I have been looking for ways to completely remove the All, Published, and Trash webpages for USERS other than the me, the Administrator.
So the scenario for me is: I have registered users (which I ...
13
votes
3answers
61k 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 ?
...
5
votes
3answers
44k views
Count how many posts in category
This is what I'm trying to do:
if number of posts is greater than 20 -> display link to another page (which shows all posts)
if number of posts is less than 20 -> don't display the link
So far I've ...
9
votes
2answers
18k 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 ...
6
votes
2answers
9k views
Disable Attachment Pages Completely
I would like to disable all attachment pages completely. I Googled it, but there's just information on how to redirect to parent post or homepage. That's not what I would call an elegant solution. Why ...
4
votes
1answer
3k views
Pretty URL with add_query_var
I'm trying to add a 'sub post' to each post on my site, eg
site.com/product-one/changelog
site.com/product-two/changelog
site.com/product-three/changelog
This is the code I'm using atm, which I ...
3
votes
2answers
3k views
Limit the post for differents custom post type in the same wp_query
I have three custom post type:
books
magazine
videos
Now i want to limit the number of post for custom post type, for example:
books => 3 post
magazine => 2 post
videos => 1 post
I used a query ...
2
votes
2answers
3k views
Counting words in a post
How can I count words in a post? Something like the one displayed just below the post?
Can someone please show me the code for getting this. I have been searching everywhere.
4
votes
2answers
2k views
count number of posts (public , private , protected) by category name
I wanted to count number of posts (public, private, protected) according to a category name suppose blog . To get all the posts no matter what category i used $total_pages = wp_count_posts()->...
2
votes
1answer
10k views
Related posts display randomly by tag
I would like to ask that what code should i add in order to make my related posts by tag to display randomly? I got this code from somewhere else.
<?php $orig_post = $post;
global $post;
$tags = ...
37
votes
4answers
138k 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' => '...
8
votes
4answers
26k views
Front end post editing using a form
I have a custom-post type with the standard meta boxes and some custom fields. How could I edit a post through a form in the frontend?
14
votes
2answers
31k 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 ...
20
votes
3answers
8k 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 ...
6
votes
3answers
6k views
Setting a custom sub-path for blog without using pages?
Warning: fairly pedantic request ahead.
I have a design that makes use of posts (I.e., the blog) and a custom post type called "howto". The site front page ("/") has a template that displays the ...
2
votes
1answer
15k views
I am trying to create a simple frontend form for posting
i am trying to learn and create some deeper things with Wordpress. My goal is to create a code/script/plugin that will allow me to post from the frontend.
I have seen many plugins, like templatic ...
1
vote
2answers
18k views
Open WordPress Posts in Bootstrap Modal
I am looking for some assistance in opening WordPress posts in the Bootstrap Modal.
Right now I have a home page with a grid that pull posts.
I have it setup so that each post is in a square box and ...
8
votes
1answer
4k views
Linking Two Post Types
and thanks in advance for your help.
I've done some searching, and this question has been answered a couple of times with reference to the "posts 2 posts" plugin, but the documentation on that is ...
12
votes
2answers
24k 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 ...
9
votes
2answers
20k views
How to Change Order of Posts in Admin?
How can I change the order of posts in the admin dashboard, so they display alphabetically according to title, rather than latest first?
8
votes
3answers
5k views
Update post counts (published, draft, unattached) in admin interface
I am working on a multi-user WordPress setup and have made it so a particular type of user can only see and interact with posts, images, pages etc that they have authored. The code to make this happen ...
7
votes
4answers
9k views
How can I convert Posts into Custom type posts?
I have a Wordpress site that I just updated to 3.1. I want to make use of custom post types now, my question is how can I assign (transfer?) a post to a newly created custom post type ?
For example, ...
3
votes
2answers
7k views
Group Posts by First Letter of Title
I am working on a website that is using posts as a way to manage glossary articles similar to the example website below. I would like to find a way to display articles alphabetically and grouped by a ...
2
votes
3answers
17k views
How to remove images from showing in a post with the_content()?
Trying to learn more about creating my own themes and not using any plugins I wanted an ability to display all the images in a post excluding the thumbnail in my single-foobar.php file and I can do ...
5
votes
2answers
15k views
Add a checkbox to post screen that adds a class to the title
I'm needing some posts to have different title colors than others, and I figured this would be most conveniently accomplished by some sort of check box on the post creation/edit screen. How would I go ...
2
votes
5answers
56k views
Display content from a specific category
I'm trying to get my news page to display content from one category only (number 3) but I cant seem to get it to work. Instead of just displaying posts from category 3 it displays posts from all ...
8
votes
5answers
16k views
How to get post creation date?
I suppose getting the first revision of a particular post and get the date, right ?
How to do that?
3
votes
2answers
25k views
$post->ID not working
I have the following code and while get_the_ID() works, $post->ID does not, why?
$the_query = new WP_Query( array(
'post_type' => 'custompost',
) );
while ( $the_query->...
2
votes
2answers
9k views
How can I edit a post from the frontend?
I have learned how to create a post from the frontend but how about editing it ?
This is the code I am trying to create a simple frontend form for posting
Thank you
1
vote
1answer
2k views
Create Post tabs in single-{content-type}.php with Custom Field values
My requirement is exactly similar to Tabbed Post.
I have Advanced Custom Fields (ACF) plugin to store data.
So pulling up the requirement from the wordpress support thread:
Movie Summary | ...
0
votes
2answers
7k views
adding a custom css class to post
essentially I need to be able to add a class to a post when it show in the list (say index.php) so when in the back end you can say oneCol, twoCol, threeCol and it will then output this within the ...