Forum Replies Created

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter bleedblue07

    (@bleedblue07)

    the global $wpdb; worked. So that’s all good now. For now I’m going to continue php on posts and pages. If I ever understand your code, maybe I’ll try to figure out how plugins work another time.

    So is the post_id a built name that wordpress recognizes or could we have named that anything like “penguin”?

    I will need to be able to limit getting points to one time for anything. So not just when someone lands on a page or post. So for example, if they click a submit button on that page it’s 15 points, maybe a like button on the same page for 5 points, then just for going to that page (since maybe it’s a new article I want people to read) they get 10 points, etc.

    Now that I figured out how to insert something in general, I’m just trying to break down your code a little at a time and figure out what it’s going to do.

    Thread Starter bleedblue07

    (@bleedblue07)

    Ya I’ll be inserting into the new wp_user_points table I created. I just wanted to copy and paste the exact code to make sure that even worked haha. Which I wish I could say does work with adding the missing “. Now it gives me this error:

    Fatal error: Call to a member function insert() on a non-object in /homepages/8/d195441424/htdocs/test/wp-content/plugins/allow-php-in-posts-and-pages/allowphp.php(373) : eval()’d code on line 1

    I understand your hello world example so thanks for that. But with your code: $query = “INSERT INTO wp_user_points (user_id, post_id, points) VALUES (“.$user_id.”, “.$post_id.”, “.$points.”) ON DUPLICATE KEY UPDATE points = “.$points.” … I’m still confused. Since we’re trying to insert and not echo why do we need the values joined. Don’t we want them to each go into there own column?

    Thread Starter bleedblue07

    (@bleedblue07)

    I’ve had a little time to do some research but am still having trouble. Before I tried to get the code you posted above to work I just wanted to to be able to insert anything to any table. Yet somehow that isn’t working either.

    I found a site that explains $wpdb and I copied a code from there exactly except changed the user_id from 1 to 4. This is the code:

    $wpdb->insert($wpdb->usermeta, array(“user_id” => 4, “meta_key” => “awesome_factor”, “meta_value” => 10), array(“%d”, %s”, “%d”));
    ?>

    This is the error:
    Parse error: syntax error, unexpected ‘%’, expecting ‘)’ in /homepages/8/d195441424/htdocs/test/wp-content/plugins/allow-php-in-posts-and-pages/allowphp.php(373) : eval()’d code on line 1

    I’m trying to google the errors I get first but I can’t seem to figure it out. Any ideas?

    Also I couldn’t find anything on this part of your code VALUES (“.$user_id.”, “.$post_id.”, “.$points.”) Why do you have . inside the ” “?

    Thread Starter bleedblue07

    (@bleedblue07)

    When you say:

    CREATE TABLE IF NOT EXISTSwp_user_points` (
    user_id bigint(20) unsigned NOT NULL,
    post_id bigint(20) unsigned NOT NULL,
    points int(11) NOT NULL,
    PRIMARY KEY (user_id,post_id)
    );`

    Are you saying I should create a new table with this criteria? Can I paste that code in somewhere and it will do that for me? Sorry I’m big time rookie.

    Thread Starter bleedblue07

    (@bleedblue07)

    You mentioned to create my own table and store the points against the user ID and post ID. What does that mean to store against the user ID? How do I do that?

    I set up a new table exactly (hopefully) the same as the usermeta table. I’m also not sure how to add things to that table like we did before with add_user_meta. I tried that with my mine: add_userpoints hoping that it would add to my userpoints table but it did not.

    Thread Starter bleedblue07

    (@bleedblue07)

    Ha. Still hard for me. But I’ll look into making a new points database. If using LIKE slows everything down as you said then I’m better off trying to do it the right way. Hopefully I can attempt this soon. Again thanks for your help.

    Thread Starter bleedblue07

    (@bleedblue07)

    I posted my follow up before I realized you responded. You’re too quick haha.

    I’ll take a look at it for sure. I’m still pretty novice at this stuff so it’ll take me a bit to understand. Will your way work for things like submit buttons or clicking links? Or will that just work for pages.

    Thread Starter bleedblue07

    (@bleedblue07)

    This is how I’m giving them points:

    if ( is_user_logged_in() ) {
    $current_user = wp_get_current_user();
    $meta_value = 32;
    add_user_meta($current_user->ID, ‘points’, $meta_value, $unique);
    }
    ?>

    I need it to somehow say if user is logged in & hasn’t already gotten points for this.

    Thread Starter bleedblue07

    (@bleedblue07)

    Awesome!!!! That works! Thanks very much for your help. I’m gonna press my luck and ask you another question. How would I limit someone to getting points just 1 time. For example, to get this thing working I have it set up so a user gets 20 points for going to a certain page, say the homepage. I don’t want them getting 20 points for that every time, just the first time. Or say 5 points if they vote on something. I don’t want them casting 10 votes and getting 50 points, just the 1. Any ideas of how to go about doing this? Where to start?

    Thread Starter bleedblue07

    (@bleedblue07)

    I found it!
    [cfdb-value] Options – mean function.

    Awesome!

    Thread Starter bleedblue07

    (@bleedblue07)

    An example would be: What percentage of people like the color blue? Then when you submit your answer, a progress bar show you the average of all the answers say 72%.

Viewing 11 replies - 1 through 11 (of 11 total)