Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Php error missing argument 2 WordPress

  • SOLVED

Her is our website:

http://greatlandtrust.org

It used to not display any errors, but now when you load it the two featured posts have a php error before them, that state:

Warning: Missing argument 2 for featured_post(), called in /home1/greatlh6/public_html/wp-content/themes/GLT/front-page.php on line 62 and defined in /home1/greatlh6/public_html/wp-content/themes/GLT/functions.php on line 472


Now, of course, I could just turn off php error warning as the site keeps working, but I'd love to resolve it if possible. I took a stab a the theme code, but nothing hopped out at my. Any suggestions?

Thanks!

Answers (3)

2016-01-15

Reigel Gallarde answers:

try this for your featured_post function...

function featured_post($post_type, $taxonomy = '') {}

this will make $taxonomy optional and not required. so that featured_post('projects') would work.


michaelmiller comments:

This did the trick! I had to delete the last } to make it work, but that was quick and easy fix. Thanks for this, and to everyone else who posted!


Reigel Gallarde comments:

you're welcome... Please don't forget to award the prize ;)

[[LINK href="http://www.wpquestions.com/user/contact/id/78975"]]You can also send me a message here if you need help on anything... [[/LINK]]

2016-01-15

Darlene Grace Arcenal answers:

Can you please paste your code from this file: /wp-content/themes/GLT/front-page.php and on this file too /wp-content/themes/GLT/functions.php.

There's something missing on your function call featured_post(). You must put arguments in here.


michaelmiller comments:

This is the line in question from front-page.php:

<section class="featurette">
<div class="featurette-item">
line 62 ---> <?php featured_post('projects'); ?>
<a class="btn" href="<?php home_url('/'); ?>projects">See All Projects</a>
</div>
<div class="featurette-item">
<?php featured_post('post') ; ?>
<a class="btn" href="<?php home_url('/'); ?>category/news-events/">Stay Connected</a>
</div>
<div class="featurette-item">
<?php dynamic_sidebar( 'homepage' ); ?>
</div>


</section>


this is from functions.php
code>
function featured_post($post_type, $taxonomy){
$args = array(
'post_type' => $post_type,
'taxonomy' => $taxonomy,
'posts_per_page' => '1',
'meta_query' => array(
array(
'key' => 'featured',
'value' => '1',
'compare' => '=='
)
)
);

// The Query
$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
the_post_thumbnail('landing-thumb');
echo '<a href="'.get_the_permalink().'"><h3>' . get_the_title() . '</h3></a>';
the_excerpt();
}
} else {

}
wp_reset_postdata();
}


function featured_testimonial(){
$args = array(
'post_type' => 'testimonials',
'posts_per_page' => '1',
'meta_query' => array(
array(
'key' => 'featured',
'value' => '1',
'compare' => '=='
)
)
);

// The Query
$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();

// if (has_post_thumbnail()) {
// the_post_thumbnail('landing-thumb');
// }else{
// echo '<img src="'.get_template_directory_uri().'/library/img/quote.png" alt="quote"/>';
// }

echo '<blockquote>' . get_the_excerpt() . '</blockquote>';
echo " <cite>".get_the_title()."</cite>";
}
} else {

}
wp_reset_postdata();
}
</code>


michaelmiller comments:

Ugh, sorry for the missing tag.


Darlene Grace Arcenal comments:

Your taxonomy is missing. On the function.php, the function call is function featured_post($post_type, $taxonomy){}. But on your front_page.php you only put featured_post('projects') and featured_post('post') . It should be


featured_post('projects', 'taxonomy_name') and featured_post('post', 'taxonomy_name')


Replace taxonomy_name with the taxonomy_name of your post types. I hope I make sense.

2016-01-15

Luis Abarca answers:

Try this code, i updated your hardcoded category and post type links.


<section class="featurette">

<div class="featurette-item">

line 62 ---> <?php <strong>featured_post('projects', 'category')</strong>; ?>

<a class="btn" href="<?php <strong>echo get_post_type_archive_link('projects')</strong>; ?>">See All Projects</a>

</div>

<div class="featurette-item">

<?php <strong>featured_post('post', 'category')</strong> ; ?>

<a class="btn" href="<?php <strong>echo get_category_link('news-events')</strong>; ?>">Stay Connected</a>

</div>

<div class="featurette-item">

<?php dynamic_sidebar( 'homepage' ); ?>

</div>

</section>