Get and Trim Full Post Content in WP Query

Simple task, but it isn't working: <?php $content = apply_filters( 'the_content', get_the_content() ); $contentWithoutHTML = wp_strip_all_tags($content); $pos = strpos($contentWithoutHTML, " ", 100); $contentFinal = substr($contentWithoutHTML,0,$pos ); echo $contentFinal . "..."; ?> My post is way over 100 characters long (with spaces), and yet I get strpos(): Offset not contained in string error, which leads me to believe it isn't actually pulling the entire content string. But I applied filters like I believe I should... please assist. Also sometimes even if …
Category: Web

REGEXP_REPLACE in post_contet

So, basically, I want to remove trailing slashes from specific domain urls. For example: https://www.example.com/here/postname/ into https://www.example.com/here/postname I have 10.4.21-MariaDB which should support REGEXP_REPLACE function. This is my query: UPDATE wp_posts SET post_content = REGEXP_REPLACE(post_content, '(http\S+)\/(\s|$)', '$1'); or this one more specifically: UPDATE wp_posts SET post_content = REGEXP_REPLACE(post_content, '(https:\/\/www\.example\.com\/here\/\S+)\/(\s|$)', '$1'); which according to regular expressions should work: https://regex101.com/r/slLbgg/1 What am I doing wrong? Any kind of help is appreciated! :) This is the result:
Category: Web

How to create WP Editor using javascript

I am trying to create some kind of repeated fields and for that, I want to create a new wp editor with some unique ID. So my question is there any way to create wp_editor using any js? same as we get using <?php wp_editor() ?> WordPress function. I have tried using tinyMCE .init( { mode : "exact" , elements : "accordion_icon_description_"+response.success.item_count }); but it prints very basic editor which is I think not same as of WordPress post content …
Category: Web

WP_Query() order by post content lenght?

How do I order a post query by the length of the post content? $orderby = ?; $query = array( 'posts_per_page' => 10, 'post_status' => 'publish', 'orderby' => $orderby, 'order' => 'DESC', ); $the_query = new WP_Query($query);
Category: Web

How can I extract or parse data from post contents' shortcodes into an array?

I'm migrating from one Visual Page editor to another. I'm extracting the texts surrounded by the shortcode opening and closing tags. Before I write my own parsing script, I wanted to make sure that Wordpress didn't already have a solution for this, or something else didn't already exist either. I feel like this is a common need that there may already be something to handle it. Here is an example of the post_content data. As you can see this can …
Category: Web

How to wrap all titles generated by Gutenberg "Heading" block with <span> tag

Gutenberg is still relative new concept, so I lack experiences (and the Internet lacks good tutorials). My goal it to wrap all heading titles generated by Gutenberg's "Heading" block with the &lt;span&gt; tag. So instead following code &lt;h2&gt;Tips and trics&lt;/h2&gt; it renders this way &lt;h2&gt;&lt;span&gt;Tips and trics&lt;/span&gt;&lt;/h2&gt; How to start? It's JS or PHP job? Is there any filter family? What documentation search for on Wordpress.org?
Category: Web

add css to only body text

In my single wordpress posts I want to apply a padding of 100px to the left and right. The problem is that when I apply it to .single .post-content the images also get a padding. However, I want all of the images on the posts pages to be set to 100%. Is there a way to separate the actual body text and the images? This seems like a fairly simple question. But I can't figure it out. Any help is …
Category: Web

form to post multiple inputs into post_content

I have a form, with multiple inputs that I am trying to get posted to the wordpress "post_content". I am able to get the title field and only one other field to post successfully, only when making a field name "description" instead of "description[]", but have no idea how I can get the rest to submit into the post_content. I would like the inputs posted like the image I have created below. Here is the code I currently have that …
Category: Web

ACF flexible content block not showing on live site (works locally)

I've made a flexible content section in ACF for a specific category that allows the user to post text and different image galleries onto their post. This all works perfectly whilst I'm on my localhost but now I've uploaded the site none of the content is showing. My code is quite messy but the code in my single.php is below and this is the link to a live post https://www.exoticsoftware.co.uk/2021/12/01/pendas-fen/, the only things that show on the page are the …
Category: Web

Wordpress API Create post content

I am basically trying to duplicate wordpress pages using the Wordpress API. I do get the page content using &quot;GET /wp/v2/pages/&quot; endpoint. I receive the the JSON data which includes: &quot;content&quot;: &quot;&lt;style&gt;/*! elementor - v3.5.5 - 03-02-2022 */\n.elementor-heading-title{padding:0;margin:0;line-height:1}.elementor-widget-heading .elementor-heading-title[class*=elementor-size-]&gt;a{color:inherit;font-size:inherit;line-height:inherit}.elementor-widget-heading .elementor-heading-title.elementor-size-small{font-size:15px}.elementor-widget-heading .elementor-heading-title.elementor-size-medium{font-size:19px}.elementor-widget-heading .elementor-heading-title.elementor-size-large{font-size:29px}.elementor-widget-heading .elementor-heading-title.elementor-size-xl{font-size:39px}.elementor-widget-heading .elementor-heading-title.elementor-size-xxl{font-size:59px}&lt;/style&gt;&lt;h3&gt;Abi '22 me But when I use this content to send a request to &quot;POST /wp/v2/pages&quot; endpoint including the same content it looks really crappy. As you can see, I use elementor. Is that the reason it …
Category: Web

image resizing on post content without css and html tags

Background: I am using WordPress posts for Newsletter. I am importing the posts through an api and use them in a Newsletter tool to send them out. I am downsizing the featured image before feeding to the Newsletter tool. But now I am facing some troubles, sometimes I have High resolution post content images. Issue: I need to resize those inner images of post content but without using any css and html image tags attributes as I am using them …
Category: Web

How to display tags with post_content

I have this code to display the content of a specific post outside the loop (actually in the archive.php template file). How do I include the tags? &lt;?php $my_id = 1576; $post_id_1576= get_post($my_id); $content = $post_id_1576-&gt;post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]&gt;', ']]&gt;', $content); echo $content; ?&gt;
Category: Web

post_content with line breaks

I want to be able to get post_content with line breaks. What is the best way to do it? I previously use the_content() which was working fine until I needed to install a plugin that adds share buttons on each post. Since then the output of my the_content includes texts from the share buttons. I tried to use post_contents which contains the correct content I need to output on my template file but the problem is the line breaks were …
Category: Web

WordPress post using block editor displays error when adding the string "cmd.exe"

Today a member of our content team reported that when they attempted to save a post in block editor mode, they continually received an error. Updating failed. The response is not a valid JSON response. After some debugging steps we determined that the string &quot;cmd.exe&quot; was to blame. When that string was present the author always got the above error. But when the string was gone or had a space after the &quot;.&quot;, the post saved and displayed just fine. …
Category: Web

How do I display/pull posts from subdomains to the landing page (domain) in WordPress Multi-site?

I have 8 sites in my multi-site network: Group Landing site (domain) Group 1 site (subdomain 1) Group 2 site (subdomain 2) Group 3 site (subdomain 3) Group 4 site (subdomain 4) Group 5 site (subdomain 5) Group 6 site (subdomain 6) Group 7 site (subdomain 7) Essentially, Groups 1 to 7 will have separate contents. However, the Group Landing site will have content from both. I would rather not have the user enter the content twice. The post must …
Category: Web

Is there any way to get list of all possible filter hooks for all post types?

I would like to code a plugin that injects the custom content to any type of post (post, page, product, any others) but I would like to allow the users to let them select the place of content too. Such as; before/after the title, before/after the content, before/after the comment section, and all other possibilities (e.g. the_content_more_link filter etc). As you know, there are many plugins, themes, custom post type plugins that they create their own custom filter hooks (e.g. …
Category: Web

Is there a way to get rendered html content of a WP post after updating?

I tried adding a filter at the content etc but that one just gives access to content stored in wp_posts. I am interested in getting the rendered html with meta tags etc for a post, after it is updated. How can I do this? I can do, but it does not look like the best option to me as the blog might have a paywall and this code would fail. What else is available? add_action( 'save_post', 'my_save_post_function', 10, 3 ); …
Category: Web

Add data attribute of post_id for Internal links

I noticed that internal links to other posts have data- * Attribute. One of Post ID. And the other of Post Type. (As in screenshot). The problem is, it's only in the block editor (Gutenberg). And not in the classic editor. The question is, is it possible to add this data, even in the classic editor. Thank you. I want, When the mouse goes over a link. An AJAX request will be made, with the post ID data. Then WordPress …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.