Looking through the code it seems like it’s not finding the taxonomy that I input. Here’s the source:
$cpt_onomy->wp_set_object_terms( $meetup_ID , ‘goal-slug-that-user-enters’, ‘goals’ , true )
What hook are you using that runs this code? Most likely this code is being run before your CPT-onomy is defined.
Thanks for the response! My functions.php looks like this:
<?php
//Create post types meetups and skills
require_once('functions/type-meetups.php');
require_once('functions/type-skills.php');
require_once('functions/type-skills-profiles.php');
require_once("functions/type-messages.php");
require_once("functions/type-goals.php");
require_once("functions/type-organizations.php");
require_once("functions/type-positions.php");
require_once("functions/type-schools.php");
require_once("functions/type-schools-profiles.php");
//Allow users to sign-in with email
require_once('functions/signin-email.php');
require_once('functions/remove-admin-slug.php');
//Functions to add friends and partnerships
require_once("functions/friend-functions.php");
require_once("functions/partner-functions.php");
?>
Then the partner-functions.php looks like this:
<?php
function add_meetup($sender_ID, $recipient_ID, $pitch, $goal, $skill, $meetup_date){
//echo $sender_ID."<br><br>". $recipient_ID."<br><br>".$pitch."<br><br>". $goal."<br><br>".$skill."<br><br>". $meetup_date;
$sender = get_userdata(intval($sender_ID));
$recipient = get_userdata(intval($recipient_ID));
$meetup = array(
'post_title' => "Meetup between $sender->first_name $sender->last_name and $recipient->first_name $recipient->last_name",
'post_content' => $pitch,
'post_status' => 'publish',
'post_type' => 'meetups',
'comment_status' => 'open',
);
$meetup_ID = wp_insert_post( $meetup );
global $cpt_onomy;
$cpt_onomy->wp_set_object_terms( $meetup_ID , 'stars', 'goals' , true );
add_post_meta($meetup_ID, 'possible_dates', $meetup_date);
add_post_meta($meetup_ID, 'sender', $sender_ID);
add_post_meta($meetup_ID, 'recipient', $recipient_ID);
exit();
wp_redirect('http://www.wisevice.com/meetups/'.get_post( $meetup_ID )->post_name);
}
if ($_POST["sender_ID"] && $_POST["recipient_ID"] && $_POST["add_partnership"]){
add_meetup($_POST["sender_ID"],$_POST["recipient_ID"], $_POST["pitch"], $_POST["goal"], $_POST["skill"], $_POST["meetup_date"]);
}
if(isset($_GET["confirm"]) && isset($_GET["confirm_ID"])){
update_post_meta($_GET["confirm_ID"], 'confirmed_date' , $_GET["confirm"]);
wp_publish_post( $_GET["confirm_ID"] ) ;
}
?>
It’s just called when the page loads, but I’m not using a hook. I’ve tried including the partner-functions.php in functions.php using the wp_loaded hook and it did change the error message. The function just returned a blank array.
You’re going to have to use a hook in order to access your CPT-onomy because they’re not defined until the ‘init’ hook runs. I recommend using the ‘wp_loaded’ action to access your CPT-onomy.
Thanks for the help! Now I’ve created a hook for the wp_loaded action and it’s just giving a blank array.
Here’s the hook code
<?php
add_action('wp_loaded','addpart');
function addpart(){
if ($_POST["sender_ID"] && $_POST["recipient_ID"] && $_POST["add_partnership"]){
$sender_ID = $_POST["sender_ID"];
$recipient_ID = $_POST["recipient_ID"];
$pitch= $_POST["pitch"];
$goal= $_POST["goal"];
$skill = $_POST["skill"];
$meetup_date = $_POST["meetup_date"];
//echo $sender_ID."<br><br>". $recipient_ID."<br><br>".$pitch."<br><br>". $goal."<br><br>".$skill."<br><br>". $meetup_date;
$sender = get_userdata(intval($sender_ID));
$recipient = get_userdata(intval($recipient_ID));
$meetup = array(
'post_title' => "Meetup between $sender->first_name $sender->last_name and $recipient->first_name $recipient->last_name",
'post_content' => $pitch,
'post_status' => 'publish',
'post_type' => 'meetups',
'comment_status' => 'open',
);
$meetup_ID = wp_insert_post( $meetup );
global $cpt_onomy;
print_r($cpt_onomy->wp_set_object_terms( $meetup_ID , 'stars', 'goals' , true ));
add_post_meta($meetup_ID, 'possible_dates', $meetup_date);
add_post_meta($meetup_ID, 'sender', $sender_ID);
add_post_meta($meetup_ID, 'recipient', $recipient_ID);
wp_redirect('http://www.wisevice.com/meetups/'.get_post( $meetup_ID )->post_name);
}
}
?>
If I var_dump the $cpt_onomy variable I get this : object(CPT_TAXONOMY), which makes me think that it IS registered and accessible. This is working on every other page I need it to. It’s just this page that’s a problem. This code is on the search page. Could that change anything?
I think the problem is solved. For some reason using the intval of the meetup_ID made it work. Any clue why?
Actually I think it was the hook thing. Thanks for the help though! You’re great.