Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP - Wordpress Syntax error

Posted on 2013-11-18
4
Medium Priority
?
504 Views
Last Modified: 2014-01-17
Hello all,
I am hoping (begging!) for a little help with my syntax here ;)
I am using Types Custom fields and would like the data to display through another plugin...I have mostly figured out how to get the data for each field that has been filled in, but am STUCK when it comes to the syntax in this area to insert a link if the data exists, and apply a class to it. Here's what I have so far:
function ajax_result($arg, $id,$pagenumber){
		   $apiclass = new ajaxwpqsfclass();
		  // The Query
			$query = new WP_Query( $arg );
			$html ='';
			// The Loop
		if ( $query->have_posts() ) {
			$html .= '<h1>'.__('Search Results :', 'AjWPQSF' ).'</h1>';
			while ( $query->have_posts() ) {
				$query->the_post();
					$html .= '<h2 class="entry-title">'.get_the_title().'</h2>';
					$html .= '<div class="one_third">';
					$html .= '<article>'.get_the_post_thumbnail($post_id, 'large').'';
					$html .= '</div></article>';
					$html .= '<div class="two_third last">'.get_the_content().'';
					$html .= '<article>'.types_render_field("address", array("output"=>"HTML","show_name"=>"true"));'</article>';
					$html .= '<article>'.types_render_field("park-location", array("output"=>"HTML","show_name"=>"true"));'</article>';
					$html .= '<article>'.types_render_field("allowable-uses", array("output"=>"HTML","show_name"=>"true"));'</article>';
					$html .= '<article>'.types_render_field("zoning", array("output"=>"HTML","show_name"=>"true"));'</article>';
					$html .= '<article>'.types_render_field("total-size", array("output"=>"HTML","show_name"=>"true"));'</article>';
					$html .= '<article>'.types_render_field("total-acreage", array("output"=>"HTML","show_name"=>"true"));'</article>';
					$html .= '<article>'.types_render_field("max-ceiling-height", array("output"=>"HTML","show_name"=>"true"));'</article>';
					$html .= '<article>'.types_render_field("rail-served", array("output"=>"HTML","show_name"=>"true"));'</article>';
					$html .= '<article>'.types_render_field("pdf-summary", array("output"=>"HTML","show_name"=>"true"));'</article>';
					$html .= '<article><a class="button small default" href="'.types_render_field("contact-cedc", array("output"=>"raw")).'">'.get_the_title().'</a></article>';
					$html .= '</div>';
					$html .= '<div style="clear:both;"></div>';
					$html .= '<div style="margin-top:40px;margin-bottom:20px" class="demo-sep sep-single"></div>';

			}

			$html .= $apiclass->ajax_pagination($pagenumber,$query->max_num_pages, 4, $id);
		 } else {
					$html .= __( '<h2>No Properties Match Your Criteria</h2><br/>¿Please search again', 'AjWPQSF' );
				}
				/* Restore original Post Data */
				wp_reset_postdata();

			return $html;

	   }	

	}//end class

Open in new window

The problem area is here:
$html .= '<article><a class="button small default" href="'.types_render_field("contact-cedc", array("output"=>"raw")).'">'.get_the_title().'</a></article>';

Open in new window


as you can see.....I am obviously a php idiot, and would GREATLY appreciate any help anyone could offer!

The desired output would be a button that displays the words "Contact CEDC" (which is the field name)which links to the url entered via the custom field "contact-cedc" (which is a single line text field), only if that field has data in it. (I can change this to a url field if necessary.)

PLEASE, any help would be very much appreciated!!!
Thank you so much!
The url where you can see the above code in action is here :

http://www.carolinebusiness.com/newsite/property-search/
then click the "Search" button.

Thanks!
0
Comment
Question by:drgleockler
  • 2
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
James Rodgers earned 2000 total points
ID: 39657860
take out all the semi colons in between the lines

));'<
$html .= '<article>'.types_render_field("address",
array("output"=>"HTML","show_name"=>"true"));'</article>';
-------------------------------------------------------------------------^
pretty sure you mean for these to be . (periods)
0
 

Author Comment

by:drgleockler
ID: 39658302
You're awesome!!!
Thank you so much!
One last question....any idea how to tell it to only display the link if the custom field has a value?  So that it's not displaying the link for empty fields?
You completely made my f*****g night!
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 39659313
before you set
$html .= '<h1>'.__('Search Results :', 'AjWPQSF' ).'</h1>';

add a line

if  ($customfield != ''){

//close after the else
}

where $customfield is the field value you want to check
0
 

Author Comment

by:drgleockler
ID: 39666781
Thank you so much for this, but I think I need more details (I'm really clueless with php...sorry!)

Here's the existing code:

function ajax_result($arg, $id,$pagenumber){
           $apiclass = new ajaxwpqsfclass();
          // The Query
            $query = new WP_Query( $arg );
            $html ='';
            // The Loop
        if ( $query->have_posts() ) {
			
					$html .= '<div class="post-content"><div class="title"><h2>'.__('Search Results :', 'AjWPQSF' ).'</h2><div class="title-sep-container"><div class="title-sep"></div></div></div></div>';
            while ( $query->have_posts() ) {
                $query->the_post();
                    $html .= '<h2 class="entry-title">'.get_the_title().'</h2>';
                    $html .= '<div class="one_third">';
                    $html .= '<article>'.get_the_post_thumbnail($post_id, 'large').'';
                    $html .= '</div></article>';
                    $html .= '<div class="two_third last">'.get_the_content().'';
                    $html .= '<article>'.types_render_field("address", array("output"=>"HTML","show_name"=>"true")).'</article>';
                    $html .= '<article>'.types_render_field("park-location", array("output"=>"HTML","show_name"=>"true")).'</article>';
                    $html .= '<article>'.types_render_field("allowable-uses", array("output"=>"HTML","show_name"=>"true")).'</article>';
                    $html .= '<article>'.types_render_field("zoning", array("output"=>"HTML","show_name"=>"true")).'</article>';
                    $html .= '<article>'.types_render_field("total-size", array("output"=>"HTML","show_name"=>"true")).'</article>';
                    $html .= '<article>'.types_render_field("total-acreage", array("output"=>"HTML","show_name"=>"true")).'</article>';
                    $html .= '<article>'.types_render_field("max-ceiling-height", array("output"=>"HTML","show_name"=>"true")).'</article>';
                    $html .= '<article>'.types_render_field("rail-served", array("output"=>"HTML","show_name"=>"true")).'</article>';
                    $html .= '<article><a class="button small default" href="'.types_render_field("pdf-summary", array("output"=>"raw")).'">Download PDF</a><span style="padding-right:10px;"></span><a class="button small default" href="'.types_render_field("contact-cedc", array("output"=>"raw")).'">Contact CEDC</a></article>';
                    $html .= '</div>';
                    $html .= '<div style="clear:both;"></div>';
                    $html .= '<div style="margin-top:40px;margin-bottom:20px" class="demo-sep sep-single"></div>';
 
            }
 
            $html .= $apiclass->ajax_pagination($pagenumber,$query->max_num_pages, 4, $id);
         } else {
                    $html .= __( '<h2>No Properties Match Your Criteria</h2><br/>?Please search again', 'AjWPQSF' );
                }
                /* Restore original Post Data */
                wp_reset_postdata();
 
            return $html;
 
       }    
 
    }//end class
	
}// end if class

Open in new window


Right now, that code displays both "buttons" at the end of the description, one that says "Download PDF" one that says "Contact CEDC."

The Contact field should always be set, so I don't need an if-then for that, but some properties have a PDF summary that has been uploaded into a custom field "pdf-summary" and some properties don't.

My issue is that the above code displays the link to download the PDF when the PDF doesn't exist.  I would like the button to show up exactly how it does above, but only if there's an uploaded file into the custom field "pdf-summary."

If there hasn't been a pdf uploaded, I want the button"download the pdf" to disappear and just keep the contact button as is.

Could you possibly let me know exactly what to insert in the above section to achieve that result?  I'm unclear specifically on the "else" part of your previous instructions.  Do I have to tell it what to do in both cases? If....then do this (all of the above parameters) else (do all parameters except the pdf summary part)???

I cannot tell you how much I appreciate all of your help!
Thanks so much...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question