Tuesday, December 13, 2022
HomeWordPress Developmentphp - WordPress Constructed-In search operate not working correctly

php – WordPress Constructed-In search operate not working correctly


I want 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 possibility, it returns solely these two articles, not all of them. Any thought?

In fact, Indexing is enabled, have Yoast search engine optimisation put in, sitemap is common, up to date, however search doesn’t returns right outcomes.

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 can retrieve all posts
));

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

  // Add the put up 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 put up 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()
{
    // Test that Broadcast is enabled.
    if ( ! function_exists( 'ThreeWP_Broadcast' ) )
        return;
    // Load the published information for this put up.
    international $put up;
    $broadcast_data = ThreeWP_Broadcast()->get_post_broadcast_data( get_current_blog_id(), $post->ID );
    // This put up have to be a baby. Test for a mum or dad.
    $mum or dad = $broadcast_data->get_linked_parent();
    if ( ! $mum or dad )
        return;

    // Fetch the permalink
    switch_to_blog( $mum or dad[ 'blog_id' ] );
    $blog_name = get_bloginfo( 'identify' );
    $permalink = get_post_permalink( $mum or dad[ '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