39

You can use get_page() to return the $post object of a static page: $page_id = 302; $page_object = get_page( $page_id ); echo $page_object->post_content; Edit Similarly, you can use get_post() to return the $post object of a post: $post_id = 302; $post_object = get_post( $post_id ); echo $post_object->post_content;


30

Both answers so far are correct but a more thorough answer seems warranted. If you use this: $content = wpautop( $post->post_content ); you're applying the one function that adds paragraph tags to post content. wpautop() is one of many functions (including plugin functions at times) that hooks onto the_content, so if you do this: $content = ...


29

Every post update in WordPress is handled by the wp_update_post function. This function has some defaults, and for post_content_filtered the default value is '' (empty string). Once the defaults are merged with args passed to function via wp_parse_args it means that every time a post is updated and post_content_filtered is not explicitly passed, it is set ...


26

I believe this should work: $getPost = get_the_content(); $postwithbreaks = wpautop( $getPost, true/false ); echo $postwithbreaks; The second argument in wpautop can be up to you whether it's true of false, see the link below. It is described as follows: (boolean or integer) (optional) Preserve line breaks. When set to true, any line breaks remaining ...


25

WordPress 5.0+ has a function for this: parse_blocks(). To see if the first block in the post is the Heading block, you'd do this: $post = get_post(); if ( has_blocks( $post->post_content ) ) { $blocks = parse_blocks( $post->post_content ); if ( $blocks[0]['blockName'] === 'core/heading' ) { } }


10

If you have the unfiltered_html capability then you can use JS. Admins and editors have this capability by default. Personally I use a plugin for fine control of my users' capabilities, but you can make this change easily in code: $role = get_role( 'administrator' ); $role->remove_cap( 'unfiltered_html' ); $role = get_role( 'editor' ); $role-&...


7

Found the solution: $content = apply_filters('the_content', $post->post_content);


7

There are a few ways I can think of to handle this: Do it once for all current posts Do it at runtime before displaying posts (either by filtering the_content, or with jQuery) Do it with important! in your CSS - as you mentioned Each method is a legitimate way of tackling this and each carries pros and cons. I usually take option 3 because it is the ...


6

to get the content of the post outside the loop you can write something like this global $post; $content = $post->post_content; if ( !empty( $content ) ) : echo $content; endif;


6

Thanks to Jacob Peattie's comment I can answer this using JS only. Actually we did something similar, but prior 4.8 and it wasn't this easy, so we did use wp_editor() in the end. But now, you can do so using wp.editor object in JavaScript. There are 3 main functions wp.editor.initialize = function( id, settings ) { Where id is The HTML id of the ...


4

When the wp_enqueue_scripts action fires, the main query has already run and the posts are in the global $wp_query. We just need to grab the ID from each object in $wp_query->posts, the wp_list_pluck function makes that easy: function wpd_get_post_ids(){ if( is_archive() ){ global $wp_query; $post_ids = wp_list_pluck( $wp_query->...


4

I think the best way is remove it and then print the content out of any textarea, but just as html: add_action('load-post.php', 'read_only_content'); function read_only_content() { if ( ! current_user_can('manage_options') ) { // change the cap with the wanted one $scr = get_current_screen(); remove_post_type_support( $scr->post_type, 'editor' ...


4

Second method to get post content with p tag is echo wpautop( $post->post_content );


4

Okay, this always seems to happen to me. I spend ages looking for an answer and finally decide to give up and post here and then one more search finds enough to solve it. Anyway, this is what worked for me: update wp_posts set post_content = replace(post_content, '[/tab] [tab title="1024x576"] <table class="screenshot-table">', '[tabby title="1024 ...


4

I wonder if you could override the [rev_slider] with this kind of wrapper: add_shortcode( 'rev_slider', function( $atts = array(), $content = '' ) { $html = ''; // Your custom banner HTML $banner = '<div id="bannerHTML"><!-- banner HTML goes here --></div>'; // Append your banner HTML to the revslider's output if( ...


3

OK, SO this is what I found out, the data <object>...</object> was the culprit. Wordpress sanitizes the input before committing to the database. Other non allowed tags include <embed>...</embed> I've seen this solution online $postData = array( ... 'filter'=>true ... ); However, some people say that's a security ...


3

Create a shortcode to embed the content. This will always be synchronized. Sample code from an older project. Just updated. :) GitHub: https://gist.github.com/3380118 · This post in German (auf Deutsch) on my blog. <?php # -*- coding: utf-8 -*- /** * Plugin Name: T5 Embed Post Shortcode * Description: Embed any page, post or custom post type with ...


3

The following will allow you to limit content to any word count you like based upon whether the user is part of a certain user role or not. The function can be improved and or made more efficient but at least it provides you the basis for filtering your content without having to physically edit the content or run any complex regular expressions. add_filter(...


3

You need to setup CSS settings for alignleft class of your theme: .alignleft, img.alignleft { /* ... */ display: inline; float: left; /* ... */ } And you need to add editor stylesheet where the same CSS will be presented. Create editor-style.css file in your theme, put content CSS settings there and call add_editor_style(); from you ...


3

change the_ID() to get_the_ID(). calling the_ID() prints the post's ID, while get_the_ID() simply returns it and allows you to use it further on. reference : get_the_ID()


3

If your content include shortcodes, you should use: $post_id = 22; $post_object = get_post( $post_id ); echo do_shortcode( $post_object->post_content );


3

There's a few things you need to do here, you need to modify your add_action() to accept additional arguments and you need to specify whether to use the data before the update or the data after the update. Try something like this: function send_media_emails($post_id, $post_after){ if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; ...


3

You can make use of featured images as suggested by @gmazzap in comments. This featured image will not be included in post content. However, if you already have your images included in post content, then you need to strip the post content down in two parts, as you've said in your question. I have two functions, one that returns all the images (or any html ...


3

This isn't possible with a standard WP query, and you'll have to leverage the use of posts_where before the WP_Query is called. function the_dramatist_filter_where($where = ''){ $where .= " AND trim(coalesce(post_content, '')) <>''"; return $where; } In the above, we're simply only selecting posts where the column post_content isn't empty. ...


3

If i get your question correct, you want the post_content formatted like the content put out by the_content, right? Change your upper code like this: global $post; $content = apply_filters('the_content',$post->post_content); This does everything to your content that would be performed when outputting it by the_content(); If you only want the p and b ...


3

You need to escape the value for use in an HTML attribute with esc_attr(): echo "<input style='width:450px;' type='text' placeholder='The Title' name='the_title' value='" . esc_attr( $val ). "'></input>";


2

You shouldn't be using query_posts() here, but rather WP_Query(). (Search WPSE for query_posts if you want to know wy.) <?php $custom_query_args = array( 'post_type' => 'page', 'post_parent' => '50', 'post_status' => 'publish', 'orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => '100' ); $...


2

I may be misinterpreting you, but I think what you want to do is run through strip_shortcodes $page_data['content'] = strip_shortcodes($page->post_content); $page_data['content'] = apply_filters('the_content', $page_data['content']); Alternately you could conditionally hook that function to the_content as demonstrated on the Codex Page.


2

I don't know about the code you are trying to use, personally I would never use a solution that excludes results, it's very possible the item being searched for is in those results and excluding them is only a degradation of service. Instead you can use the search.php template file to adjust how your search results are displayed, there is a very handy ...


2

A potential solution would be to first get rid of the Post Template plugin and just use the default single.php to render single post views. Then add a get variable onto the end of your imagemap links, so they're something like domain.com/post-name/?view=lightbox Then filter the single_template to load your lightbox view template when the GET var is ...


Only top voted, non community-wiki answers of a minimum length are eligible