skip to Main Content

I’d want to edit the content of one of my posts using this way, but it’s not working.

Does this filter affect the php output or the raw php file?

add_filter( 'the_content', 'multiple_string_replacements');
function multiple_string_replacements ( $contentt ) {
    if ( is_single('15467') && in_the_loop() && is_main_query() ) {
   
    $condition = true;
  
    if($condition){
        $urlsdothejob = "link.com";
        
        $text = array(
        "$variable1" => "$urlsdothejob",
        "$variable2" => "$urlsdothejob",
    );

    $contentt = str_ireplace(array_keys( $text ), $text, $contentt);

    };
    }
    return $contentt;
}

2

Answers


  1. If you know the conditions that you’re looking for, you should be able to write an IF statement to match.

    if ($constantvalue == "anothervalue") {
      // make local changes 
    }
    

    Can you give an example of what you’re trying to do? It’s hard to understand the request with such little information.

    Login or Signup to reply.
  2. Try like this hope its working for you.

    while(have_posts()):
    
        $ID = get_the_ID();
    
        $data1 = get_post_meta($ID,'meta_key',true);
        $data2 = get_post_meta($ID,'meta_key',true);
    
        if($data1 == $data2) {
            update_post_meta($ID,'meta_key','meta_value');
        }
    
    endwhile;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search