Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [get-post]

The tag has no usage guidance.

0
votes
0answers
31 views

Loop (for search results) returning right posts, but wrong post type

Hoping this isn't already asked/answered, but it's a tough one to search. I've got a site based on the Flatsome theme which uses custom post types (through various plugins). The search page works in ...
0
votes
3answers
21 views

Show content from multiple pages (not posts) on home page

On my home page I'd like to display the title and content from a few pages (about page, contact page, etc.). It looks like the template tag get_post can be used, but I'm not savvy enough with PHP to ...
1
vote
1answer
348 views

Using apply_filters('the_content', $custom_query->post_content) alters output

Disclaimer: sorry if this has been asked/answered, but I couldn't find the right search phrase to get something similar. I'm editing a template for a site I did not build, and I stumbled across funky ...
1
vote
1answer
75 views

Wordpress function to get term or post object by id

Currently to differentiate between post and term objects I use short piece of code: $object = get_post($id); if ( ! $object ) { $object = get_term($id); } print_r($object); Is there a function ...
2
votes
2answers
3k views

Difference between the_content() and get_post()?

I'm working on tweaking a theme and I need to explode the post content to remove some text. The following code is what I am using: $custom_Get_Post_Title = explode('|',get_post()->post_content); ...
0
votes
2answers
152 views

Get posts under custom taxonomy and custom post type

I've created a page with list of custom terms: Under each Term, i need to show every posts with post_type = 'courses'e taxnonomy = 'courses_category' What will be the query to display those records? ...
1
vote
1answer
277 views

Cannot get grandparent object

I'm using the following code in order to get the ID of the current page's grandparent and great grandparent: <?php $current = get_post($post->ID); $grandparent = $current->post_parent; ...
0
votes
1answer
95 views

Get post first paragraph without html tag [duplicate]

please can someone help me the correct code to filter the first paragraph of any post without any form of html-tag in the source code. i used function get_first_paragraph(){ global $post; $...
0
votes
1answer
342 views

(Frontend AJAX) get post data WITH image thumbnail?

I return data using the post id through AJAX. Now, what is the best way to "merge" the image thumbnail ( get_the_post_thumbnail( $id, 'medium' ) ) into the data returned from the server? I need this ...
0
votes
1answer
73 views

WP overwrites my setup_postdata() setup

I'm trying to display under a (very) custom URL a post in a template of my choice. My post's ID in this example is 1008 and my template name '/singles/lecture.php'. Im the future will check the URL ...
0
votes
1answer
216 views

Why does get_post() not return anything?

Inside my functions.php I use get_post() or similar (such as get_the_title()) inside some of my functions. It does not return anything. Why? And how to fix that? P.S: And I can not really add ...
1
vote
2answers
1k views

How to pass arguments to add_action() or retrieve return value of called function?

I'd like to call a function Y($arg) when the hook X is fired. Alternative: catch the return value from function Y(), which is called via add_action('X', 'Y'); in function W, which contains the ...
0
votes
1answer
79 views

How to call get_post()?

I have a sidebar on my site and there I want to show the current post's meta information, such as the last modified date, the author and more. Thus I wrote the following function: function ...
0
votes
1answer
715 views

get posts by tag to showing in a widget

Hi there dear developers! i make a widget in my wordpress theme to show 5 last video-based posts in that. and my video posts have a 'video' tag. how i can query that posts by tag to showing there? ...
-1
votes
2answers
50 views

Displaying post/page info on a homepage using get_post()

I've been asked to make some changes to a Wordpress site and the previous dev has displayed information from certain current pages on the homepage. What's confusing me is how they've managed to do ...
0
votes
2answers
257 views

Get post format and use it as a CSS class in different spans

I use a <span> inside the loop and I would like to get each post format the post is containing as a class in separate spans. Example: If the post format is video and private: I would like to ...
7
votes
1answer
2k views

get_post() vs global $post or $GLOBAL['post']

I'm writing a widget plugin and need access to post information. I've seen people using 3 different approaches: global $post; if ( isset( $GLOBALS['post'] ) ) $post = $GLOBALS['post']; $post = ...
5
votes
2answers
870 views

What is an alternative to get_page_by_title()?

I'm coding a theme where I want to display information in the footer that's only available on a template page. I have been using get_page_by_title() which works well if you know what the page will be ...
0
votes
1answer
1k views

Custom Fields with get_post()

I am using get_post() to call a single Wordpress post using it's post ID. I have successfully managed to pull the content / title of the post but would like to also pull custom fields also. The code ...
0
votes
1answer
328 views

Which method is faster to get a single post?

If I want to get only a single post with the featured thumbnail. Which of the function is better to use (for the performance) get_post or WP_Query?
5
votes
1answer
998 views

How to get the image EXIF date/time and use it for the WP post date/time

I currently have the following working function. add_action('add_attachment', 'create_post_from_image'); function create_post_from_image($id) { if (wp_attachment_is_image($id)) { $image = ...
1
vote
1answer
368 views

Loading post template that contains a nested loop with ajax

I'm currently working on a project where I'm loading a post with ajax. I'm using get_post() to get the post, setup_postdata() to setup the post data, and get_template_part() to load the template ...
0
votes
2answers
679 views

make get_post work in the loop

I'm getting a post by id with get_post(); $post = get_post(17); $page = get_post_meta(17); setup_postdata( $post ); include($page['_wp_page_template'][0]); After getting the post I include a ...
0
votes
1answer
1k views

Best way to check if a post with specific meta exists

I am building a function in wordpress that reads an XML file and imports 100-500 events as a post type to wordpress. The events have a lot of meta data that is saved as post meta. One of the meta data ...
0
votes
1answer
65 views

Function to get the name in database table from the comma separated string

I already created admin column in WP using this code: add_filter('manage_pages_columns', 'page_custom_cols', 10); function page_custom_cols($pages_columns, $post_type) { $pages_columns['user_group'] =...
0
votes
1answer
76 views

Modifying Wordpress XML-RPC Built-Ins

In short, I want to be able to modify the wp.getPost response to also return additional data, like the permalink. I thought it would be as easy as just calling the same function the xml-rpc code ...
1
vote
1answer
55 views

Obtain page data and use regular loop

Is there a way to obtain the data from a certain page outside the regular flow, more efficiently than via get_post($id)? I know that I can get for example the title with $post = get_post($id); $title ...
1
vote
0answers
71 views

Formatting get_post content doesn't allow JS content to function properly

I am currently pulling in the latest post on a category page based on which category you click on. When you click on the category "Code Examples" you see this: I am using the Crayon syntax ...
0
votes
0answers
57 views

getpost content with all formatting for admin pages

All My post usually uses various plugin based data manipulations (Like visual layout, grouping, plugin css, etc) And now I want to render a post content in my admin page. On using following code: $...
0
votes
2answers
2k views

Get the excerpt by page ID from another blog in a wordpress multisite?

I am trying to get the first paragraph on a page where page ID=2 and blog ID=1. I want to display this paragraph on a page in blog id=2. I have added the following code to the template page. //gets ...
0
votes
2answers
3k views

Get current post data into array?

I'm trying to achieve a similar effect to get_page($id), but with the current post acting as the argument for get_post(). Something like this pseudocode: get_post($this=>ID); . Seems simple, but I ...
0
votes
1answer
78 views

Get post by Category in custom template

I want get all categor and after that i want get 5 post per category. but my code not work! http://pastebin.com/vxDSGGZk <?php $categories=get_categories(''); foreach($categories as $...
0
votes
1answer
3k views

Retrieving custom field value with get_post?

There's no mention of custom fields values in Get_post's codex page. Is it impossible to use get_post to get a custom field value of some post, and if so, is it necessary to perform a whole loop just ...
0
votes
1answer
644 views

How to get post meta in functions?

I set an email button in functions php. The email is sent when clicking on a front-end update post button. The problem is: the email is sent but I can't get the post title to appear in the post. I ...
0
votes
4answers
5k views

How to limit the characters shown on the page - get_content

I've the below php to display the content of the post id#9 on my 'home page' of my site, so that whenever the client updates the page, it's reflected on the homepage as well - rather than having to ...
0
votes
2answers
953 views

Get post content intro text on category.php?

For some categories on my site there's introduction text that needs formatting (so using the category description isn't an option) and placing at the top of categories.php. I've added a post ID to ...
0
votes
1answer
290 views

using query_posts to pull posts out of a category in a while loop. Getting odd echo

I have a custom template file I've been workin on. I have this code performing a loop after it queries posts from a certain category. This works and I have each post configured with styled divs, but ...
1
vote
2answers
6k views

Elegant way to include only published posts with get_objects_in_term()?

The obvious way is to iterate through the resulting array of IDs, get_post for each and test against post_status == 'publish'. But I wonder whether this could cause memory issues since get_post will ...