If else echo help - AJAX maybe?

Hi there,

I am trying t display some text depending on whether a user has something bookmarked.

This is what I have:

$bookmarked =  \MyListing\Src\Bookmarks::exists( (int)$post_id , get_current_user_id() );
    $classes =  'bookmarked';
    $bmText = "Remove Bookmark";
    $fontClass = "fa fa-regular fa-heart";
       $bmText = "Add Bookmark";    
    if ( $is_caching ) {
      $classes = '<var #saved></var>';

I am then trying to echo it out using:

$HTML .= '<div class="listing-details actions c27-footer-section">
    <div >    <ul>    <li tooltip=" ' . $bmText . '">text</li></ul></div>';

However, I am only getting the “Bookmarked” version of text appearing.

Can anyone see what I have wrong with my if/else? I think it may be because the bookmark button AJAX/dynamic so changes when you click the button without the page loading.

Many thanks!

Hello, I am newbie in Ajax but you should ask ChatGPT to correct your piece of code. I usually ask Chat GPT for debugging and explaining me the code. You will have an answer in just 1 minute…

Without seeing what the custom class function is returning, AI or no, it cant solve the problem, because the problem isnt readily syntactical.

var_dump $bookmarked when you think it should be false. What does it say it is?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.