WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] What's wrong? Fetching meta value (10 posts)

  1. mariostella
    Member
    Posted 3 years ago #

    I have this function to fetch all the custom values (the email) of an array of post IDs stored in the browser's cookies:

    <?php    if (wpfp_get_cookie()):
            foreach (wpfp_get_cookie() as $post_id) {
                $email = get_post_meta($post_id, 'email', true);
    			echo "".'$mail->AddAddress'."".'"('."$email".')"'."; ";
    		}
     	else:
        endif;
    ?>

    The function wpfp_get_cookie() is thus defined:

    function wpfp_get_cookie() {
        return $_COOKIE[WPFP_COOKIE_KEY];
    }

    Problem: $email is not being spit out. The meta values are not found. But the function works since when I echo any word or symbol it gets spit out as many times there are instances in the browser's cookies.

    Can anyone help please?

  2. forunner
    Member
    Posted 3 years ago #

    you use $post_id into your get_post_meta.

    are you sure your foreach define it correctly ? try a echo $post_id in the foreach.

    in the echo, $mail->AddAddress won't be interpreted because it's between quotes (is that normal?)

  3. mariostella
    Member
    Posted 3 years ago #

    Thanks for your reply.
    Yes, I want that to produce a php script, therefore I am quoting the php to echo. This is part of an email php script.

    I am sorry I did not quite understand what you mean for trying an echo $post_id in the foreach.

    I forgot to mention I am not a php expert :)

  4. forunner
    Member
    Posted 3 years ago #

    <?php    if (wpfp_get_cookie()):
            foreach (wpfp_get_cookie() as $post_id) {
    
              echo $post_id;
    
                $email = get_post_meta($post_id, 'email', true);
    			echo "".'$mail->AddAddress'."".'"('."$email".')"'."; ";
    		}
    
        endif;
    ?>

    to see if your function works like you want

    it should return an id

  5. mariostella
    Member
    Posted 3 years ago #

    Aha! You were right! It returns the word "Added" instead of an ID. Indeed the function is part of the add to your favorites plugin, and I am trying to fetch the email of those posts that have been favored.
    I will have to look for a function that returns the ID and not a word.
    I am going trial and error. Would you happen to know a better way? Do you know the plugin at all?
    Thanks

  6. forunner
    Member
    Posted 3 years ago #

    I don't know

    maybe you could try an SQL request?

  7. mariostella
    Member
    Posted 3 years ago #

    I tried for the past day, but could not get to understand how to make an SQL request...I searched the forums and google, but got totally confused. Would you have a quick example of what it should look like? Thanks for all your help, really.

  8. forunner
    Member
    Posted 3 years ago #

    this link should help you

    look into your phpmyadmin to see where the datas you want are stored ! wp_1_posts maybe?

  9. mariostella
    Member
    Posted 3 years ago #

    Hi,
    Thanks again. The core issue here is that the IDs I am looking for are not stored in the database, so a DB query is not gonna pull anything (philosophically speaking, as I have no idea as I am no expert), what I am interested in is in the cookies of the user, and the plugin that gets them is my wp favorites, therefore I need to capitalize on those functions in order to pull the data I need.
    With the function in "standalone" mode on another page of the site I can get those emails meta values just fine, but when I stick the function in another page, especially the one sending the email,and especially inside the SMTP code, it returns only the number of instances, but not the meta value. In other words if I tell it to echo something defined like a character or string of characters (i.e. a word) the word gets repeated x amount of times as many as are the posts in the browser's cookies, but I would not be able to pull specific data about those posts like ID, meta values and keys and so on.

  10. mariostella
    Member
    Posted 3 years ago #

    Hate to bump, but has anyone any idea please? The developer won't help. Thanks in advance.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.