jarvis
Members-
Posts
543 -
Joined
-
Last visited
Everything posted by jarvis
-
Thanks @mac_gyver If I've understood you, you mean: $cookie_name = 'defaultLanguage'; $cookie_value = $_GET["language"]; if ($cookie_value != ''){ $cookie_value = $_GET["language"]; setcookie($cookie_name, $cookie_value, time() + (86400 * 30), '/'); // 86400 = 1 day }else{ $cookie_value = 'English'; setcookie($cookie_name, $cookie_value, time() + (86400 * 30), '/'); // 86400 = 1 day } Sadly that doesn't work either (assuming I've interpreted what you meant!?)
-
Thanks Ansego. OK, I now have: if (isset($_GET['language'])){ setcookie ('defaultLanguage', $_GET['set'], time()+(86400 * 30), '/', 'localhost', '0'); // 86400 = 1 day $set_language = $_GET['language']; }elseif (isset($_COOKIE['defaultLanguage'])) { $set_language=$_COOKIE['defaultLanguage']; } else { setcookie ('defaultLanguage', 'English', time()+(86400 * 30), '/', 'localhost', '0'); $set_language = 'English'; } If I then do: echo $set_language; It shows English, it then shows the language I want as soon as I submit the form. However, once I then navigate off of the page, it reverts back to English. Not sure if this is progress or not Lol
-
Thanks Ansego but still no joy. I wonder if it's because I'm using Wordpress but this should make no difference as it's included within the header file Ginerjm, are you referring to domain and secure? If so, I thought they were optional so no need to include them
-
Thanks Ch0cu3r However, if I refresh the page, it still says Cookie with name "defaultLanguage" value is: English If I went the session route, won't the session only last as long as the browser window is open?
-
Hi All, I seem to be getting in a right mess with this, so hope someone can help. I'm simply trying to set a cookie called 'defaultLanguage'. It will initially be set to English and when someone completes a form, the form value is then passed and used in the cookie. here's my code: $cookie_name = 'defaultLanguage'; $cookie_value = $_GET["language"]; if ($cookie_value == ''){ $cookie_value = 'English'; }else{ $cookie_value = $_GET["language"]; } setcookie($cookie_name, $cookie_value, time() + (86400 * 30), '/'); // 86400 = 1 day I then use this to test/check: $cookie_name = 'defaultLanguage'; if(!isset($_COOKIE[$cookie_name])) { print 'Cookie with name "' . $cookie_name . '" does not exist...'; } else { print 'Cookie with name "' . $cookie_name . '" value is: ' . $_COOKIE[$cookie_name]; } If I clear my browser cookies, this is what happens: On initial page load it says: Cookie with name "defaultLanguage" does not exist... If I reload the page or move to another, it says: Cookie with name "defaultLanguage" value is: English If I then complete my form, ?language=French is added to the URL, however, it still says: Cookie with name "defaultLanguage" value is: English I think I' missing something obvious but can't see for looking!! Any help is much appreciated
-
Am so sorry! I thought it was a 'mark as solved' overall, not a specific part of the thread. I've altered this now and would like to say thanks once again for the help!
-
Thanks cyberRobot, was hoping to just use something similar to the code I had if poss?
-
Hi All, Incredibly simple I'm sure! I have an if while loop with a counter. $i = 0; How can I rewrite this part : if($i == 1 || $i == 5 || $i == 9 || $i == 13 ){ I tried if($i % 4 === 0){ but that's not right Thanks
-
Combine Totals from while loop and foreach loop (Wordpress)
jarvis replied to jarvis's topic in Applications
Thanks sKunKbad, I did think of that but because I need to loop round twice, thought this would be the better approach. Especially as I need to grab the ID value from the first loop and pass it to the second. Not something I thought could be done by querying the DB direct - unless I've totally missed the obvious!? -
Hi All, I really hope someone can help. I've a custom post type called 'countries'. Each region can have sub regions. For example; Europe is made up of Uk, France, Germany etc Now, the site is a job site, when you add a job, you can add it to a country/sub country. What I'm trying to do is show a total number of jobs. It works apart from when you have a job in Europe and jobs listed in sub regions, France etc I have 4 jobs listed. 1 in Europe 3 in France It should therefore show 4 but instead, I can't get the totals to combine. I think I'm missing something obvious!! Any help is much appreciated <ul> <?php #List all the countries $countries_query = array( 'post_type' => 'countries', 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'name', 'hide_empty' => 1, 'post_parent' => 0 ); $loop = new WP_Query( $countries_query ); while ( $loop->have_posts() ) : $loop->the_post(); $countries_key = 'country'; $countries_value = get_the_ID(); $countries_sql = "SELECT count(DISTINCT pm.post_id) FROM $wpdb->postmeta pm JOIN $wpdb->posts p ON (p.ID = pm.post_id) WHERE pm.meta_key = '$countries_key' AND pm.meta_value = '$countries_value' AND p.post_type = 'jobs' AND p.post_status = 'publish' "; $countries_count = $wpdb->get_var($countries_sql); #echo $countries_count; #debug ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php #If parent country has jobs, then show the total #if ($countries_count != 0) : echo '('.$countries_count.')'; endif; ?> <?php #List all jobs linked to a country via the Country ID $posts = get_posts(array( 'numberposts' => -1, 'post_type' => 'countries', 'post_parent' => get_the_ID() )); if($posts) { $total = 0; foreach($posts as $post) { $meta_key = 'country'; $meta_value = get_the_ID(); $sql = "SELECT count(DISTINCT pm.post_id) FROM $wpdb->postmeta pm JOIN $wpdb->posts p ON (p.ID = pm.post_id) WHERE pm.meta_key = '$meta_key' AND pm.meta_value = '$meta_value' AND p.post_type = 'jobs' AND p.post_status = 'publish' "; $count = $wpdb->get_var($sql); #Combine the totals of all the sub country jobs $thecount = $count[0]; $total += $thecount; } #end foreach $posts $new_total = $countries_count + $total; echo "($new_total)"; } #endif $posts #If parent country has jobs, then show the total if ($countries_count != 0) : echo '('.$countries_count.')'; endif; ?> </li> <?php endwhile; ?> </ul> Thanks in advanced.
-
I really hope someone can help! I currently use the following to get a URL: $pageURL=''; $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; $filename = basename($pageURL); I could then echo $filename and use it elsewhere in my code. However, I've an issue with the a URL that contains Googles UTM code, for example: http://www.domain.co.uk/2013/02/14/?utm_source=COMPANY&utm_medium=email&utm_term=NewsletterLink&utm_campaign=Newsletter&utm_content= How can I use the above but strip out the ?utm... I've tried a preg_replace but couldn't seem to get it working. Any help is much appreciated! TIA
-
Solved! The limit was set to 5 but the feed only had 2, so 3 were just blank results, hence the date being what it was. Sometimes the obvious and just hard to see
-
Hi All, I hope someone can help. I've the following code which retrieves info from a Wordpress RSS feed nad converts it into PHP: <?php $rss = new DOMDocument(); $rss->load('http://wordpress.org/news/feed/'); $feed = array(); foreach ($rss->getElementsByTagName('item') as $node) { $item = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue, ); array_push($feed, $item); } $limit = 5; for( $x=0; $x<$limit; $x++ ) { $title = str_replace(' & ', ' & ', $feed[$x]['title']); $link = $feed[$x]['link']; $description = $feed[$x]['desc']; $description = substr($description, 0, 500); $date = date('l F d, Y', strtotime($feed[$x]['date'])); echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />'; echo '<small><em>Posted on '.$date.'</em></small></p>'; echo '<p>'.$description.'</p>'; } ?> All works well and grabs what I need. However, at the bottom of the returned info, I get another loop of results which shows: Posted on Thursday January 01, 1970 Posted on Thursday January 01, 1970 Posted on Thursday January 01, 1970 But I can't see how or why this gets created? Can someone assist? TIA
-
Hi All, Apologies is this is the wrong forum, I wasn't sure if it should be Wordpress or MySQL! I hope someone can help! I've the following SQL which pulls info from Wordpress using the CIMY EXTRA Fields plugin. What I need to do is grab the last_name from the usermeta table too. However, I simply can't get it to work. Here's what I have: SELECT $wpdb->users.ID, display_name, cimy_sector.VALUE as sector, cimy_company.VALUE as company FROM $wpdb->users, {$wpdb->prefix}cimy_uef_data cimy_sector, {$wpdb->prefix}cimy_uef_fields cimy_fields1, {$wpdb->prefix}cimy_uef_data cimy_company, {$wpdb->prefix}cimy_uef_fields cimy_fields2 WHERE $wpdb->users.ID = cimy_sector.USER_ID AND $wpdb->users.ID = cimy_company.USER_ID AND cimy_sector.FIELD_ID = cimy_fields1.ID AND cimy_fields1.NAME ='SECTOR' AND cimy_sector.VALUE = '".$companyType."' AND cimy_company.FIELD_ID = cimy_fields2.ID AND cimy_fields2.NAME ='COMPANY' AND cimy_company.VALUE LIKE '%".$search_by."%'"; Now this works fine and retrieves the correct data. I simply can't get another table and the result I need, any help is much appreciated! TIA
-
Thanks Thorpe, what I'm saying is, I'm sure it's easy & obvious but can't work it out!
-
Hi All, Need some assistance/pointing in the right direction. I need to create a list of projects you can scroll up/down. When you then click a project, a box appears (expands) and you can then scroll left and right to view the details. Any assistance is much appreciated as can't even think about where to start - yet know it's easy & obvious! Thanks
-
Aaaah ball! Solved it, realised I needed to start the loop differently: query_posts( 'post_type=locations&order=desc&orderby=id'); if (have_posts()) : $i = 0; while ( have_posts() ) : the_post(); ?> <li><a href="http://localhost/aaa/<?php echo $post_name; ?>?locationID=<?php echo $i; ?>"><img src="<?php echo get_post_meta($post->ID, 'thumbnail', true); ?>" title="<?php echo get_post_meta($post->ID, 'location_region', true); ?> :: <?php echo get_post_meta($post->ID, 'location_type', true); ?>" /></a></li> <?php $i++; endwhile; endif; ?> Sorry!
-
Hi, I have the following code: <?php query_posts( 'post_type=locations&order=desc&orderby=id'); if (have_posts()) : while ( have_posts() ) : $i++;the_post(); ?> <li><a href="http://localhost/aaa/<?php echo $post_name; ?>?locationID=<?php echo $i; ?>"><img src="<?php echo get_post_meta($post->ID, 'thumbnail', true); ?>" title="<?php echo get_post_meta($post->ID, 'location_region', true); ?> :: <?php echo get_post_meta($post->ID, 'location_type', true); ?>" /></a></li> <?php endwhile; endif; $i = 0; ?> It works perfectly, however, instead of starting at 1, I wish it to start at 0. How would I do this? Thanks
-
I'm trying to output it on test.php However, I'm starting to think that as the file test.php is being loaded independtly (i.e. called in). It will error as the file will need to be calling in some of the core functions of Wordpress - but I may be wrong!?
-
Ok. I've been playing around but am still none-the-wiser! So if I post my code, it may help as what you're saying implies that yes, I can output the php value as I have captured it. I've got header.php with this: <script> $(document).ready(function(){ $.ajaxSetup({cache:false}); $(".locationID").click(function(){ var post_id = $(this).attr("rel"); //alert($(this).attr('rel')); $("#single-home-container").html("loading..."); $("#single-home-container").html(post_id); $.post("test.php", {"locationID": post_id}, function (txt) { alert(txt); }); return false; }); }); </script> I then have footer.php which lists all the dynamic links: <ul> <?php $args = array( 'post_type' => 'locations', 'order' => 'DESC' ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); ?> <li><a href="#" rel="<?php the_ID(); ?>" class="locationID"><?php the_title(); ?></a></li> <?php endwhile; wp_reset_query(); ?> </ul> In footer.php, I also include a call to a file: <?php include(TEMPLATEPATH."/test.php"); ?> In test.php I want to show the result of the selected link: echo 'Footer with location id of ' . $_POST['locationID']; $the_location_id = $_POST['locationID']; <?php $args = array( 'post_type' => 'locations', 'posts_per_page' => 1, 'p' => $the_location_id , ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); ?> <?php the_title(); ?> <?php endwhile; wp_reset_query(); ?> So As you can see, I'm trying to get the id of the clicked link, pass it to a php variable which I can then use in a query. From what's shown above, surely that's correct? But if I echo the variable echo $the_location_id; nothing is shown Sorry to keep posting but I really would like to get to grips with it and see what I've done wrong. Thanks again
-
I seriously cant believe this is so difficult. I simply want to grab a value, assign it to php and then use it in a query. Is there a simple option I've overlooked? Surely if alert($(this).attr('rel')); displays the value, there must be a simple way to not alert it to the public and assign it to $this_value or something, which can then be used anywhere on the page?
-
Ok thanks Thorpe. In which case, is it possible to return the page but without the: <html> <body> </body> </html> Thanks
-
Here's test.php <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script> $(document).ready(function(){ $.ajaxSetup({cache:false}); $(".locationID").click(function(){ var post_id = $(this).attr("rel"); //alert($(this).attr('rel')); $("#single-home-container").html("loading..."); $("#single-home-container").html(post_id); $.post("test.php", {"locationID": post_id}, function (txt) { alert(txt); }); return false; }); }) </script> </head> <body> <div id="single-home-container"></div> <hr> <?php $id = $_POST['locationID']; echo 'Result: '.$id;?> <hr> <a href="#" rel="1" class="locationID">1</a><br> <a href="#" rel="2" class="locationID">2</a><br> <a href="#" rel="3" class="locationID">3</a><br> <a href="#" rel="4" class="locationID">4</a><br> </body> </html> Thanks
-
Thanks again Thorpe However, that just outputs the entire page again. I simply need the id value. It's also not assigned to the php <?php echo 'Footer with location id of ' . $_POST['locationID'];?> I'm simply trying to get it so I can pass the ID into a query later on, so need to physically see that the ID can be assigned or printed out. Thanks