R
R
rennameduser_34322021-09-07 21:14:19
WordPress
rennameduser_3432, 2021-09-07 21:14:19

Not writing data to a WordPress variable?

while( have_posts() ) : the_post();
    
    $html = '
      <a href="'.the_permalink().'" class="post-item__photo">
        <img src="'.the_post_thumbnail_url().'" alt="">
      </a>
      <a href="'.the_permalink().'" class="post-item__title">'.the_title().'</a>
      <p></p>
      <a href="'.the_permalink().'" class="post-item__link">
        <svg width="44" height="44" viewBox="0 0 44 44" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M42.9546 9.79777V40.4852H32.6078V21.113V18.6988L30.9007 20.4059L8.76622 42.5403L1.41421 35.1883L23.5487 13.0539L25.2558 11.3468H22.8416L3.46936 11.3468L3.46936 1L34.1568 1L42.9546 9.79777Z" stroke="black" stroke-width="2"/></svg> 
      </a>
    ';
    $array[] = $html;
    
    
  endwhile;
  print_r($array);


(In this case, the content itself is displayed, but it is not written to a variable, and I need to transfer the data to the frontend)

In an array
spoiler
(
    [0] => 
      <a href="" class="post-item__photo">
        <img src="" alt="">
      </a>
      <a href="" class="post-item__title"></a>
      <p></p>
      <a href="" class="post-item__link">
        <svg width="44" height="44" viewBox="0 0 44 44" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M42.9546 9.79777V40.4852H32.6078V21.113V18.6988L30.9007 20.4059L8.76622 42.5403L1.41421 35.1883L23.5487 13.0539L25.2558 11.3468H22.8416L3.46936 11.3468L3.46936 1L34.1568 1L42.9546 9.79777Z" stroke="black" stroke-width="2"/></svg> 
      </a>
    
    [1] => 
      <a href="" class="post-item__photo">
        <img src="" alt="">
      </a>
      <a href="" class="post-item__title"></a>
      <p></p>
      <a href="" class="post-item__link">
        <svg width="44" height="44" viewBox="0 0 44 44" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M42.9546 9.79777V40.4852H32.6078V21.113V18.6988L30.9007 20.4059L8.76622 42.5403L1.41421 35.1883L23.5487 13.0539L25.2558 11.3468H22.8416L3.46936 11.3468L3.46936 1L34.1568 1L42.9546 9.79777Z" stroke="black" stroke-width="2"/></svg> 
      </a>
    
    [2] => 
      <a href="" class="post-item__photo">
        <img src="" alt="">
      </a>
      <a href="" class="post-item__title"></a>
      <p></p>
      <a href="" class="post-item__link">
        <svg width="44" height="44" viewBox="0 0 44 44" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M42.9546 9.79777V40.4852H32.6078V21.113V18.6988L30.9007 20.4059L8.76622 42.5403L1.41421 35.1883L23.5487 13.0539L25.2558 11.3468H22.8416L3.46936 11.3468L3.46936 1L34.1568 1L42.9546 9.79777Z" stroke="black" stroke-width="2"/></svg> 
      </a>
    
    [3] => 
      <a href="" class="post-item__photo">
        <img src="" alt="">
      </a>
      <a href="" class="post-item__title"></a>
      <p></p>
      <a href="" class="post-item__link">
        <svg width="44" height="44" viewBox="0 0 44 44" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M42.9546 9.79777V40.4852H32.6078V21.113V18.6988L30.9007 20.4059L8.76622 42.5403L1.41421 35.1883L23.5487 13.0539L25.2558 11.3468H22.8416L3.46936 11.3468L3.46936 1L34.1568 1L42.9546 9.79777Z" stroke="black" stroke-width="2"/></svg> 
      </a>
    
    [4] => 
      <a href="" class="post-item__photo">
        <img src="" alt="">
      </a>
      <a href="" class="post-item__title"></a>
      <p></p>
      <a href="" class="post-item__link">
        <svg width="44" height="44" viewBox="0 0 44 44" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M42.9546 9.79777V40.4852H32.6078V21.113V18.6988L30.9007 20.4059L8.76622 42.5403L1.41421 35.1883L23.5487 13.0539L25.2558 11.3468H22.8416L3.46936 11.3468L3.46936 1L34.1568 1L42.9546 9.79777Z" stroke="black" stroke-width="2"/></svg> 
      </a>
    
    [5] => 
      <a href="" class="post-item__photo">
        <img src="" alt="">
      </a>
      <a href="" class="post-item__title"></a>
      <p></p>
      <a href="" class="post-item__link">
        <svg width="44" height="44" viewBox="0 0 44 44" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M42.9546 9.79777V40.4852H32.6078V21.113V18.6988L30.9007 20.4059L8.76622 42.5403L1.41421 35.1883L23.5487 13.0539L25.2558 11.3468H22.8416L3.46936 11.3468L3.46936 1L34.1568 1L42.9546 9.79777Z" stroke="black" stroke-width="2"/></svg> 
      </a>
    
    [6] => 
      <a href="" class="post-item__photo">
        <img src="" alt="">
      </a>
      <a href="" class="post-item__title"></a>
      <p></p>
      <a href="" class="post-item__link">
        <svg width="44" height="44" viewBox="0 0 44 44" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M42.9546 9.79777V40.4852H32.6078V21.113V18.6988L30.9007 20.4059L8.76622 42.5403L1.41421 35.1883L23.5487 13.0539L25.2558 11.3468H22.8416L3.46936 11.3468L3.46936 1L34.1568 1L42.9546 9.79777Z" stroke="black" stroke-width="2"/></svg> 
      </a>
    
    [7] => 
      <a href="" class="post-item__photo">
        <img src="" alt="">
      </a>
      <a href="" class="post-item__title"></a>
      <p></p>
      <a href="" class="post-item__link">
        <svg width="44" height="44" viewBox="0 0 44 44" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M42.9546 9.79777V40.4852H32.6078V21.113V18.6988L30.9007 20.4059L8.76622 42.5403L1.41421 35.1883L23.5487 13.0539L25.2558 11.3468H22.8416L3.46936 11.3468L3.46936 1L34.1568 1L42.9546 9.79777Z" stroke="black" stroke-width="2"/></svg> 
      </a>
    
    [8] => 
      <a href="" class="post-item__photo">
        <img src="" alt="">
      </a>
      <a href="" class="post-item__title"></a>
      <p></p>
      <a href="" class="post-item__link">
        <svg width="44" height="44" viewBox="0 0 44 44" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M42.9546 9.79777V40.4852H32.6078V21.113V18.6988L30.9007 20.4059L8.76622 42.5403L1.41421 35.1883L23.5487 13.0539L25.2558 11.3468H22.8416L3.46936 11.3468L3.46936 1L34.1568 1L42.9546 9.79777Z" stroke="black" stroke-width="2"/></svg> 
      </a>
    
    [9] => 
      <a href="" class="post-item__photo">
        <img src="" alt="">
      </a>
      <a href="" class="post-item__title"></a>
      <p></p>
      <a href="" class="post-item__link">
        <svg width="44" height="44" viewBox="0 0 44 44" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M42.9546 9.79777V40.4852H32.6078V21.113V18.6988L30.9007 20.4059L8.76622 42.5403L1.41421 35.1883L23.5487 13.0539L25.2558 11.3468H22.8416L3.46936 11.3468L3.46936 1L34.1568 1L42.9546 9.79777Z" stroke="black" stroke-width="2"/></svg> 
      </a>
    
    [10] => 
      <a href="" class="post-item__photo">
        <img src="" alt="">
      </a>
      <a href="" class="post-item__title"></a>
      <p></p>
      <a href="" class="post-item__link">
        <svg width="44" height="44" viewBox="0 0 44 44" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M42.9546 9.79777V40.4852H32.6078V21.113V18.6988L30.9007 20.4059L8.76622 42.5403L1.41421 35.1883L23.5487 13.0539L25.2558 11.3468H22.8416L3.46936 11.3468L3.46936 1L34.1568 1L42.9546 9.79777Z" stroke="black" stroke-width="2"/></svg> 
      </a>
    
)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yarovikov, 2021-09-07
@rennameduser_3432

get_permalink
get_the_title
although you have chosen a strange way to transfer data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question