Articles of get post

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 pagetemplate wich contains a: while ( have_posts() ) : the_post(); If I call the_title() from outside the loop I get the right title of the post called with get_post(). If […]

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 below is how I declare custom fields in a standard wp_query: $customField = (get_post_meta($post->ID, “_mcf_customField”, true)); And […]

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? thanks.

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 add_action() statement. How do I do that? My use case: I have a function createMainPanel() that returns a string $ret to be […]

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 and add a condition when to do the action – now for tests the condition is just if […]

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 make the change twice. At the moment all the post content is being shown, I need […]

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 can’t find the it in the docs.

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 for some reason, on the side of the page, I have strange numbers being displayed. I don’t understand […]

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 highlighter plugin, which works fine, but when I use the following code to pull in the above content, it […]

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 = $post->post_title; But I prefer to use the loop, rather than picking every single page element in the way […]