r0bbiem
Forum Replies Created
-
Forum: Hacks
In reply to: update_post_meta array problemThanks catacaustic, I’m looking into that approach now.
Couple of questions…for something like this is it ok to do all my mysql interactions using the $wpdb class, or am I better off using vanilla php and mysql?
and
I have some $wpdb code for creating a table, but it strikes me that this might be something that only has to be done once ever. That leaves me wondering where to put the code…putting it in my plugin doesn’t seem to make sense. Am I wrong?
Forum: Hacks
In reply to: update_post_meta array problemThanks bcworkz
I tried some of your suggestions but in the end I’m getting around it like this
$ip = $_SERVER['REMOTE_ADDR']; $id = $_POST['post_id']; $voter_ips = get_post_meta($id, 'voter_ips', true); $voter_ips_array = explode(",", $voter_ips); //use $voter_ips_array for comparison if(strlen($voter_ips) == 0) { $voter_ips .= $ip; } else { $voter_ips .= ',' . $ip; } update_post_meta($id, 'voter_ips', $voter_ips);
Not ideal because I’m also storing a date along with my vote which I’d like to cross reference so saving and retrieving a multi-dimensional array would seem to be the most elegant solution but for now this will have to do.
I’m planning on storing the ips and dates as alternate values and then using some kind of +1 or -1 system to access and compare the two.If anyone has any more insight on this I’d love to be enlightened.
Forum: Hacks
In reply to: WP_Query in plugin causing post title issuesThanks for all the input, in the end I solved the problem by moving the array declarations into functions.php and then accessing them as global variables.
Here’s the working code: pastebin.com/vHuCdL5P
Since then I’ve also discovered get_option() and update_option() as described here https://bit.ly/aeVE97 and to me this seems like a more robust way of dealing with site-wide variables such as these.
I’ve learned a lot through this process, still not clear on what was causing my initial problem but this should help anyone experiencing the same kind of issues.
Forum: Hacks
In reply to: update_post_meta problem saving field valuesThanks bcworkz, that didn’t solve the problem but good to know.
I have a nagging feeling that I’m not defining my $meta_keys (such as ‘track_artist’) before I try to populate them, but I’m not familiar enough with this process.
Should I be using an add_post_meta() before I use update_post_meta()?
Only problem I can see with this is that add_post_meta() requires a value and I would just want to define the keys at first without populating them with values.Forum: Hacks
In reply to: WP_Query in plugin causing post title issuesAnother update, I still haven’t solved this problem, tried replacing the contents of my getArtists() function with this;
$artistPosts = get_posts('post_type=artists'); foreach($artistPosts as $post) : array_push($artistList, get_the_title()); endforeach;
Thought that by avoiding the loop the problems might disappear but my posts still seem to be mis-categorized somehow by the use of this function.
Anyone out there?
+1 Pretty please!