Solved

PHP - Wordpress Syntax error

Posted on 2013-11-18
4
487 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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now