WordPress job and resume board not working - php

i just developed a job and resume upload code for my website hoping it will work. Am using code snippets plugin to add the code.
after adding the code, i get menu shortcut on my dashboard menu: illustrated in the pic.
enter image description here
how do i develop short code to add to a page.
attached is the developed code:
// This file contains the code needed to create a job and resume plugin for your WordPress site.
// First, we need to create a function that will register the custom post type for our job and resume posts.
function register_job_resume_post_type() {
$labels = array(
'name' => 'Jobs & Resumes',
'singular_name' => 'Job & Resume',
'add_new' => 'Add New',
'add_new_item' => 'Add New Job & Resume',
'edit_item' => 'Edit Job & Resume',
'new_item' => 'New Job & Resume',
'all_items' => 'All Jobs & Resumes',
'view_item' => 'View Job & Resume',
'search_items' => 'Search Jobs & Resumes',
'not_found' => 'No jobs & resumes found',
'not_found_in_trash' => 'No jobs & resumes found in Trash',
'parent_item_colon' => '',
'menu_name' => 'Jobs & Resumes'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'job-resume' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);
register_post_type( 'job-resume', $args );
}
// We also need to create a function to register the custom taxonomies for our job and resume posts.
function register_job_resume_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => 'Job & Resume Categories',
'singular_name' => 'Job & Resume Category',
'search_items' => 'Search Job & Resume Categories',
'all_items' => 'All Job & Resume Categories',
'parent_item' => 'Parent Job & Resume Category',
'parent_item_colon' => 'Parent Job & Resume Category:',
'edit_item' => 'Edit Job & Resume Category',
'update_item' => 'Update Job & Resume Category',
'add_new_item' => 'Add New Job & Resume Category',
'new_item_name' => 'New Job & Resume Category Name',
'menu_name' => 'Job & Resume Categories'
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'job-resume-category' ),
);
register_taxonomy( 'job-resume-category', array( 'job-resume' ), $args );
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => 'Job & Resume Tags',
'singular_name' => 'Job & Resume Tag',
'search_items' => 'Search Job & Resume Tags',
'popular_items' => 'Popular Job & Resume Tags',
'all_items' => 'All Job & Resume Tags',
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => 'Edit Job & Resume Tag',
'update_item' => 'Update Job & Resume Tag',
'add_new_item' => 'Add New Job & Resume Tag',
'new_item_name' => 'New Job & Resume Tag Name',
'separate_items_with_commas' => 'Separate job & resume tags with commas',
'add_or_remove_items' => 'Add or remove job & resume tags',
'choose_from_most_used' => 'Choose from the most used job & resume tags',
'menu_name' => 'Job & Resume Tags'
);
$args = array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'job-resume-tag' ),
);
register_taxonomy( 'job-resume-tag', 'job-resume', $args );
}
// Finally, we need to register our custom post type and taxonomies with WordPress.
add_action( 'init', 'register_job_resume_post_type' );
add_action( 'init', 'register_job_resume_taxonomies', 0 );
Assist me on how to sort it out.
step on how to make it work and develope shortcode for easy installation

You would use the add_shortcode() function. This function takes two parameters: the name of the shortcode and then the callback function to display the shortcode content. See the code below.
function namespace_cpt_shortcode() {
$args = [
'post_type' => 'job-resume'
];
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
// Save the data you wish to show in the post
$postTitle = get_the_title();
$postContent = get_the_content();
//Save the data to the variable that will be returned in the shortcode.
$result = "
<div class='post-container'>
<h2>$postTitle</h2>
<p>$postContent</p>
</div>";
} // End while loop
} else {
$result = "No posts found.";
}
/* Restore original Post Data */
wp_reset_postdata();
return $result;
}
// Use add_shortcode() to create the shortcode. First parameter is the name of the shortcode and the second is the function name.
add_shortcode( 'job-listing', 'namespace_cpt_shortcode' );
If you want to add more post information to the layout, you would add it into the $result variable as that is what is being returned in the function because shortcodes require a returned value.

Related

Wordpress: Non hierarchical taxonomy to be select only one in edit posts

I have a taxonomy added with this code
function tmc_type_taxonomy() {
$type = array(
'name' => 'Types',
'singular_name' => 'Type',
'menu_name' => 'Types',
'all_items' => 'All Types',
'parent_item' => 'Parent Type',
'parent_item_colon' => 'Parent Type:',
'new_item_name' => 'New Type Name',
'add_new_item' => 'Add New Type',
'edit_item' => 'Edit Type',
'update_item' => 'Update Type',
'separate_items_with_commas' => 'Separate Types with commas',
'search_items' => 'Search Types',
'add_or_remove_items' => 'Add or remove Types',
'choose_from_most_used' => 'Choose from the most used Types',
);
$args = array(
'labels' => $type,
'hierarchical' => false,
'rewrite' => array( 'slug' => 'type' ),
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'show_in_rest' => true,
);
register_taxonomy( 'tmc_type', 'post', $args );
}
add_action( 'init', 'tmc_type_taxonomy', 0 );
And it displays like the tags in wordpress.
I want to make it like a radio box. For this, I tried to do it hierarchical which displays the checkbox instead but I could not change it to radio through jquery with the code
function checktoradio(){
echo '<script type="text/javascript">jQuery("#id").each(function(){this.type="radio"});</script>';
}
add_action('admin_footer', 'checktoradio')
Because the sidebar in edit post page is loaded dynamically. So I cannot modify the checkbox as its not created yet in the footer hook.
How do I change it to select only one?
According to the scope of the question, you need to hook your JavaScript code to the "admin_enqueue_scripts" hook in this way:
// custom css and js
add_action('admin_enqueue_scripts', 'cstm_css_and_js');
function cstm_css_and_js() {
wp_enqueue_style('admin_css', get_template_directory_uri().'/css/admin.css');
wp_enqueue_script( 'admin-js', get_template_directory_uri().'/js/admin.js', array('jquery-core'), false, true );
}
And you should put your code inside the "admin.js" file.
this is the link to study more about this hook:
https://developer.wordpress.org/reference/hooks/admin_enqueue_scripts/#:~:text=admin_enqueue_scripts%20is%20the%20proper%20hook,informs%20the%20current%20admin%20page.
But honestly, you need to focus on how you are going to apply your changes in the backend of your website.

Wordpress > Custom post type with Custom taxonomy > terms not linking to custom archive page

I am a new with wordpress, but have about 6 months experience so far so I am not a complete noob!
I have run into a problem and I just can't solve it. Any help or insights would be very welcome to get me going.
I have created a Custom post type for 'news' - All good
I have created a Custom Taxonomy for the news items - All good
I have created a 'News centre' page which displays the news along with links for the terms that are attached to the news item - All good
The term links go to the default archive.php - Not good.
I want the term links to go to a page that pulls in all the news items tagged with that term.
Here is my CPT And taxonomy function:
<?php
/**
* Register CPT News
*/
add_action( 'init', 'cpt_news' );
function cpt_news() {
$labels = array(
'name' => _x( 'News', 'post type general name' ),
'singular_name' => _x( 'News', 'post type singular name' ),
'menu_name' => _x( '+ News', 'admin menu' ),
'name_admin_bar' => _x( 'News', 'add new on admin bar' ),
'add_new' => _x( 'Add New', 'News' ),
'add_new_item' => __( 'Add New News' ),
'new_item' => __( 'New News' ),
'edit_item' => __( 'Edit News' ),
'view_item' => __( 'View News' ),
'all_items' => __( 'All News' ),
'search_items' => __( 'Search News' ),
'parent_item_colon' => __( 'Parent News:' ),
'not_found' => __( 'No News found.' ),
'not_found_in_trash' => __( 'No News found in Trash.' ),
'featured_image' => 'Add Featured Image',
'set_featured_image' => 'Select an image'
);
$args = array(
'description' => __( 'News' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions',
//'author', 'excerpt', 'trackbacks', 'custom-fields',
),
// comments was removed to disable comments.
'hierarchical' => false,
'public' => true,
'publicly_queryable' => true,
'query_var' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 2,
'can_export' => true,
'exclude_from_search' => false,
'capability_type' => 'news', //page
'has_archive' => true,
'map_meta_cap' => true,
);
register_post_type( 'news_item', $args );
}
add_action( 'init', 'cpt_news_taxonomy' );
function cpt_news_taxonomy() {
register_taxonomy( 'news_type', 'news_item',
array(
'labels' => array(
'name' => _x( 'News Topic', 'taxonomy general name', 'text_domain' ),
'add_new_item' => __( 'Add New Topic', 'text_domain' ),
'new_item_name' => __( 'New Topic', 'text_domain' ),
),
'exclude_from_search' => false,
'has_archive' => true,
'hierarchical' => true,
'show_ui' => true,
'show_tagcloud' => true,
)
);
}
?>
When I click on a news item tagged with 'Volunteering' it goes to this url: /news_type/volunteering/, which is displayed using the archive.php, even though I have created archive-news_item-volunteering.php
I am sure I am missing something really obvious!
According to the Wordpress Codex page on Template Hierarchy, you create a template file with the name of taxonomy-news_type.php. WordPress will use that to display the archive for that taxonomy. You can also use taxonomy-news_type-volunteering.php to create the template for the specific term 'volunteering' in your taxonomy.
Thanks Dan, that nailed it! I was thrown off by the fact it defaulted to archive.php and went down the wrong route. All working now, thanks! Have a great day!
Jason

Link a custom post type to its own page in wordpress

I have a CPT called businesses and have created posts within that however, when I click on any of the posts, they show a blank page. Anyone know why?
<?php
//create a custom post type for new businesses
function create_businesses() {
$labels = array(
'name' => 'Our Businiesses',
'singular_name' => 'Our Businesses',
'add_new_item' => 'Add A New Business', 'chandco',
'new_item' => 'New Business', 'chandco',
'edit_item' => 'Edit Business', 'chandco',
'view_item' => 'View Business', 'chandco',
'all_items' => 'All Businesses', 'chandco',
'add_new' => 'Add A New Business', 'chandco'
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'capability_type' => 'post',
'supports' => array('title', 'editor', 'thumbnail'),
'rewrite' => array( 'slug' => 'businesses' ),
);
register_post_type( 'businesses', $args);
}
add_action( 'init', 'create_businesses' );
?>
According to Wordpress standard, this output will handle by the "single.php" file ( Common file for all posts single view ).
But if you are getting blank page then you can try again by creating the specific file for the "businesses" custom post type posts.
Create a file called "single-businesses.php" file. So now if you click on any of the posts, Wordpress will call this specific file and generate the output.

Add new button not working for custom post type

Hello I have a very strange situation: I created a CPT (WP 4.7) and i was even able to create one custom post. However, the Add New button stopped working and simply will go to the home page. That only happens with this new CPT as the others are working correctly.
Here's the code i used:
add_action( 'init', 'create_recipes' );
function create_recipes() {
$labels = array(
'name' => 'Recipes',
'singular_name' => 'Recipe',
'menu_name' => 'Recipe',
'name_admin_bar' => 'Recipe',
'add_new' => 'Add New',
'add_new_item' => 'Add New Recipe',
'new_item' => 'New Recipe',
'edit_item' => 'Edit Recipe',
'view_item' => 'View Recipe',
'all_items' => 'All Recipes',
'search_items' => 'Search Recipes',
'parent_item_colon' => 'Parent Recipes:',
'not_found' => 'No recipes found.',
'not_found_in_trash' => 'No recipes found in Trash.'
);
$args = array(
'public' => true,
'labels' => $labels,
'description' => 'Create your own recipes',
'show_ui' => true,
'capability_type' => 'post',
'menu_icon' => 'dashicons-carrot',
'rewrite' => true,
'menu_position' => 4,
'supports' => array('title', 'editor','thumbnail')
);
register_post_type( 'recipe', $args );
}
As usual any help will be greatly appreciated

WP Custom Post Type Taxonomy - Need to create Categories

I am trying to create a custom post type called "Incentives". Within this custom post type, I would like to create a category titled "Lighting Incentives". I have created a function to register the custom post type and create the taxonomy/category. However, for some reason I am unable to register the taxonomy/category. The taxonomy/category does not appear in the WP dashboard. Also, the hierarchy of "Incentives" vs "Lighting Incentives" seems a bit mixed up. Here is my code
add_action('init', 'incentive_register');
function incentive_register() {
$labels = array(
'name' => _x('Lighting Incentives', 'post type general name'),
'singular_name' => _x('Lighting Incentive', 'post type singular name'),
'add_new' => _x('Add New', 'Lighting Incentive'),
'add_new_item' => __('Add New Lighting Incentive'),
'edit_item' => __('Edit Lighting Incentive'),
'new_item' => __('New Lighting Incentive'),
'view_item' => __('View Incentive'),
'search_items' => __('Search Incentives'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => 'lighting-incentives',
'menu_position' => null,
'parent_item' => 'Incentives',
'supports' => array('title','editor','thumbnail','excerpt','custom-fields','post-formats')
);
register_post_type( 'Incentive' , $args );
register_taxonomy_for_object_type('category','Incentive');
flush_rewrite_rules();
}
You should use lowercase for the name of your custom post type. Change this
register_post_type( 'Incentive' , $args );
register_taxonomy_for_object_type('category','Incentive');
to this
register_post_type( 'incentive' , $args );
register_taxonomy_for_object_type('category','incentive');
EDIT
You should flush your permalinks only once

Categories