Wednesday, December 14, 2022
HomeWordPress Developmentsearch - Dynamically added textual content at backside of article - non...

search – Dynamically added textual content at backside of article – non searchable by PHP code


I would like to maneuver sure articles on my web site, all of them, to a different distinctive class. I’m utilizing particular phrase which is at backside of each article, however after code execution, solely two articles are moved to new class, not all of them. Additionally once I search via all posts utilizing native Dashboard-All posts choice, it returns solely these two articles, not all of them. I assume that’s as a result of textual content just isn’t saved in database, as a result of it reveals solely when submit renders it self on frontend.
How can I embody dynamically created textual content into my code?

My code, only for reference:

<?php
// Transfer to class Breaking Information
$target_category_id = 1982;

// Get all posts that comprise the search phrase from Syndication
$posts = get_posts(array(
  's' => 'and has been printed right here with permission',
  'post_status' => 'any',
  'posts_per_page' => -1 // This may retrieve all posts
));

// Loop via the posts and transfer them to the goal class
foreach ($posts as $submit) {
  // Take away the submit from any current classes
  $current_categories = wp_get_post_categories($post->ID);
  wp_remove_object_terms($post->ID, $current_categories, 'class');

  // Add the submit to the goal class
  wp_set_post_categories($post->ID, array($target_category_id), true);
}

EDIT That particular phrase is created dynamically, as a result of I’m utilizing WP Broadcast plugin so as to add textual content on the backside of each broadcasted article, however I’m not certain is that phrase saved in database or that textual content is dynamically populated (created) each time submit is rendered on frontend.

That is the code I’m utilizing to generate message (phrase) on the backside of each article:

<?php
operate broadcasted_from()
{
    // Verify that Broadcast is enabled.
    if ( ! function_exists( 'ThreeWP_Broadcast' ) )
        return;
    // Load the printed knowledge for this submit.
    world $submit;
    $broadcast_data = ThreeWP_Broadcast()->get_post_broadcast_data( get_current_blog_id(), $post->ID );
    // This submit have to be a toddler. Verify for a guardian.
    $guardian = $broadcast_data->get_linked_parent();
    if ( ! $guardian )
        return;

    // Fetch the permalink
    switch_to_blog( $guardian[ 'blog_id' ] );
    $blog_name = get_bloginfo( 'identify' );
    $permalink = get_post_permalink( $guardian[ 'post_id' ] );
    restore_current_blog();

    // And now assemble a textual content.
    $r = sprintf( 'This text appeared in <a href="%s">%s</a> and has been printed right here with permission.', $permalink, $blog_name );
    return $r;
}
add_shortcode( 'broadcasted_from', 'broadcasted_from' );

add_filter( 'the_content', operate( $content material )
{
// Get the broadcasted from textual content.
$sc_text = do_shortcode( '[broadcasted_from]' );
// Add the textual content to the content material.
$content material .= $sc_text;
// Return the expanded content material.
return $content material;
} );

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments