Jump to content

maxxd

Gurus
  • Posts

    1,655
  • Joined

  • Last visited

  • Days Won

    51

Posts posted by maxxd

  1. Not sure how that would have happened, but dude I feel ya' - losing WIP sucks. Check to see if your editor created a temp file somewhere or if there's an automated backup. Obviously, this is one of the benefits of using git but if you're not or you didn't commit or push, it may be rough. How exactly were you running the script that an infinite loop could have wiped your file?

    • Great Answer 1
  2. Seeing as $subcategories is the common variable on both lines, I'd assume that is the problem. As of 7.2, php starting emitting a warning if the variable passed to count() isn't an array or another type that actually can be counted. I don't know what the 'knowledge template' is, but I'd bet it was developed before php7, and that sometimes there are no subcategories - this is probably leaving $subcategories null or 0, which isn't countable. Check to see if there's an updated version of the theme; if not you'll need to find where $subcategories is defined and make sure it's an array even if there aren't any subcategories to be found.

  3. I feel like something else is happening - this code works for me:

    	<script src="https://cdn.jsdelivr.net/npm/js-cookie@3.0.1/dist/js.cookie.min.js"></script>
    	<script>
    		function setCookie(){
    			Cookies.set('testing2', JSON.stringify([{
    				testing1: 'hi there',
    				testing2: 'whaddup?!?',
    				testing3: 'how you doing?',
    			}]), { expires: 3650 });
    		}
    
    		var json_string = Cookies.get('testing2');
    
    		console.log(json_string);
    
    		if(typeof json_string == 'undefined'){
    			setCookie();
    			json_string = Cookies.get('testing2');
    		}
    
    		console.log(json_string);
    	</script>

    First time I visit the page, i get 'undefined' followed by the JSON string. Subsequent visits give me the JSON string both times.

    The only real difference here is that I'm setting json_string from the cookie after I set it where you're hard-coding the value. But even then, you shouldn't be seeing the 'set new cookie' console log because after the first page load the cookie would be set.

    What does your entire script look like? Are you getting any errors?

  4. Again - you're already in php mode, so using the opening and closing php tags is redundant and will throw an error.

    Change this line:

    header('link: < https://example.com<?php echo ($_SERVER['REQUEST_URI']); ?>>; rel="canonical"');

    to this:

    header('link: <https://example.com/'.$_SERVER['REQUEST_URI'].'>; rel="canonical"');

    and see what that gives you.

  5. You're already in php, so you don't need the `<?php echo` and `?>` around the $_SERVER['REQUEST_URI']. You will, however, have to concatenate as you're using single quotes for that header string and single quotes won't interpolate php code.

    I'm not overly familiar with the `link` header so I can't say for certain, but I wouldn't be surprised if there were additional syntax errors on that line.

  6. I think I misinterpreted the original post. I read it as 'favorite of three flavors', not 'favorite three flavors'. Given that, I wouldn't recommend using an enum datatype. Personally, I'd probably go with a table to keep the flavors and another table to keep the votes. Count and group on select and everything's good to go. It's honestly just an over-engineered version of kicken's suggestion, but I have a tendency to over-engineer at the outset...

  7. To make it even simpler (maybe), you could actually have a single column in your table - use an enum with the three flavors as the values. Each row represents a vote - then you can count and group by value.

    Not sure it's worth doing this over kicken's suggestion, just another way to look at it.

  8. It's been a while since I've dealt with WooCommerce and even in my current job my interaction with WP core has been limited so ymmv, but given you're talking about WordPress plugins I assume the global $post variable is available. If I remember correctly (and a quick SO search didn't lead my brain astray) you should be able to add `$order = new WC_Order($post->id);` before the code requinix suggested if you get an error with just that code alone. WordPress relies heavily on global variables and this unfortunately makes debugging difficult at times...

    • Thanks 1
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.