I'm building a Wordpress blog that requires a custom slideshow system with an admin panel on each post admin page (sort of like how Yoast's SEO plugin has options on each page).
How would I make the admin options appear on the post admin page?
Thanks,
Charlie
You are not providing much detail about your project but you probably want to make some meta_boxes and save the data to as custom fields.
Here is a truncated example culled from something I put together for a question at wordpress.stackexchange. The details of some of the functions are not important for your question here but it illustrates the general 'how'. Follow the link for working but sincerely beta code.
// author checkboxes
add_action( 'add_meta_boxes', 'assisting_editor' );
function assisting_editor() {
add_meta_box(
'assisting_editor', // id, used as the html id att
__( 'Editorial Tasks' ), // meta box title
'editor_tasks', // callback function, spits out the content
'post', // post type or page. This adds to posts only
'side', // context, where on the screen
'low' // priority, where should this go in the context
);
}
// this is the callback that creates the meta box content
function editor_tasks( $post ) {
// function details skipped; follow the link
}
// to save the data
add_action( 'save_post', 'save_metadata');
// callback for the save hook ^^
function save_metadata($postid) {
// function details skipped; follow the link
}
Related
I've made a WordPress website people can rent cars from brokers. So I have 2 custom post types:
broker
car
There are about 10 different cars on the website. All these cars are for each broker exactly the same.
So I've created a page template page-brokers.php that lists all the brokers.
If you click on a broker, you go to the detail page of the broker single-broker.php
The URL is saferental.be/broker/broker-name
On the detail page of the broker, you'll see all the 10 different cars. If you click on a car, you go to the car detail page, which is single-car.php
The URL is saferental.be/car/car-name
At the bottom of the car detail page, is a form to contact the broker you've selected previously. As you see in the URL, there is nothing mentioned of the selected broker.
When you select a broker, its information is saved in a session and pushed into hidden fields in the form.
Everything works perfectly:
- You select a broker
- You pick a car -> go to the car detail page
- Submit the car detail page form which sends the information to the selected broker.
The result I want to have:
- If you select a broker, you go to the detail page saferental.be/broker/broker-name/ (this is already okay)
- If you select a car, you go to the car detail page which should be something like this: saferental.be/broker/broker-name/car/car-name
Test website:
http://safelease.houston-1.hybridmedia.be/
The brokers are at the bottom of the homepage.
Do you want to keep that car detail page also will available under saferental.be/car/car-name?
If not, so — just put car detail page as child page to broker and url for this page will be saferental.be/broker/broker-name/car/car-name
If you want to many different urls for the same page — try to use this plugin https://wordpress.org/plugins/mapping-multiple-urls-redirect-same-page/
I have done something similar to this myself.
This would go in your functions file:
// Setup rewrite rules something like http://yourdomain.com/broker/my-broker/car/my-car
add_action( 'init', 'rewrites_init' );
function rewrites_init() {
add_rewrite_rule(
'broker/([-a-zA-Z0-9]+)/car/([-a-zA-Z0-9]+)$',
'index.php?broker=$matches[1]&car=$matches[2]',
'top' );
}
// Add variables
add_filter('query_vars', 'add_query_vars', 0);
function add_query_vars($vars) {
$vars[] = 'broker';
$vars[] = 'car';
return $vars;
}
// catch the request for this page
add_action('parse_request', 'parse_requests', 0);
function parse_requests() {
global $wp, $wp_query;
if(isset($wp->query_vars['broker']) && isset($wp->query_vars['car'])) {
// find the car post
$posts = new WP_Query( array(
'post_type' => 'car',
'name' => $wp->query_vars['car'],
'post_status' => 'publish'
));
if(!empty($posts) ) {
// set the global query or set your own variable
$wp_query = $posts;
// set the broker variable to use in your template
$broker = get_page_by_path( $wp->query_vars['broker'], OBJECT, 'broker' );
// include your custom post type template
if (include(locate_template('single-car.php', true))) {
exit();
}
} else {
// handle error
$wp_query->set_404();
status_header(404);
locate_template('404.php', true);
exit;
}
}
}
Then in your car template, you should be able to access the $broker post variable.
After you have setup your rewrite rules, you may need to go to Admin -> Settings -> Permalinks and save to set the rewrites.
Hopefully this helps you.
I have to make two customization on my woocommerce site.
I need to know two main hooks. Someone out there please help me out!
Show custom field values to billing address on order-received page.(I added custom fields on checkout page.)
Need to include these values to customers' order-received email, too.
Thanks for stopping by.
To show custom field in order-received page you have to use
woocommerce_thankyou hook.
Here is the code:
// define the woocommerce_thankyou callback
function action_woocommerce_thankyou($order_id)
{
$my_custom_field = get_post_meta($order_id, '_billing_my_field', TRUE);
}
// add the action
add_action('woocommerce_thankyou', 'action_woocommerce_thankyou', 10, 1);
UPDARED This section after post author comment
To add custom billing fields in WooCommerce email you have to use
woocommerce_email_customer_details hook; this will be displayed just
before the customer details.
Here is the code:
add_filter('woocommerce_email_customer_details', 'custom_woocommerce_email_order_meta_fields', 10, 3);
function custom_woocommerce_email_order_meta_fields($order, $sent_to_admin, $plain_text)
{
$_billing_my_field = get_post_meta($order->id, '_billing_my_field', true);
if ($plain_text)
{
echo 'My field is ' . $_billing_my_field;
}
else
{
echo '<p>My field is ' . $_billing_my_field . '</p>';
}
}
All code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Please Note:
I have assuming that you have added a custom billing fields as $fields['billing']['billing_my_field'] using woocommerce_checkout_fields hook.
All the codes are tested and fully functional.
I have repeatedly been trying to implement the Advanced Custom Fields (ACF) plugin in the Vantage theme (from AppThemes), but without any success. I've had extensive contact with the admin of ACF, on this subject, but unfortunately we did not succeed. He advised to ask here, maybe seek for a (paid) developer, to solve this problem.
Ok, so what am i trying?
I have created a custom field group and want to implement that field group within the listing form of Vantage. To do so i have read several docs, including: http://www.advancedcustomfields.com/resources/tutorials/creating-a-front-end-form/. To be complete, based on this i did the following in the Vantage theme folder:
I created 2 custom field groups, with the id's: 88 & 139.
In Wrapper.php i added the code: <?php acf_form_head(); ?>
In form-listing.php i created 2 custom hooks, 'product_custom' and 'product_custom2': <?php do_action( 'product_custom' ); ?> <?php do_action( 'product_custom2' ); ?>
In fuctions.php i created 3 functions:
add_action( 'wp_print_styles' , 'my_deregister_styles' , 100 );
function my_deregister_styles() {
wp_deregister_style( 'wp-admin' );
}
add_action( 'product_custom' , 'productfields' );
function productfields() {
$options = array(
'field_groups' => array('post' => '88' ),
'form' => false,
);
acf_form( $options );
}
add_action( 'product_custom2' , 'productfields2' );
function productfields2() {
$options2 = array(
'field_groups' => array('post' => '139' ),
'form' => false,
);
acf_form( $options2 );
}
This actually made the custom field group show up in the listing form of Vantage. However the following things keep going wrong:
Both field groups have a WYSIWYG field. However for some reason the WYSIWYG buttons and media button stop working
I cannot fill in any text in the first WYSIWYG field. Only the second one works for that matter.
No data is stored at all after saving the listing form. On advise of the ACF admin, i tried the following in the acf-master/core/api.php file:
// run database save first
if( isset($_POST['acf_save']) )
{
$txt="Hello world!";
echo $txt;
die();
However the string does not display after saving the listing form. So the if statement is not used...
4. To display the dataon the frontend, once they are saved, I guess the default wordpress codex can be used..
I tried to be as complete as possible;) Is there anybody who can help me any further? Paid assistance is also negotiable..
Thanks a lot in advance!
Robbert
I have succeed on implementing ACF with vantage themes.
I add ACF form at vantage listing form and combine the vantage form with ACF form. with one button.
The data has been saved to database and can be called to displayed in listing area. Only add image button is not working from front-end but in back-end the button is working.
Adding <?php acf_form_head(); ?> to wrapper.php
Do this tutorial front end form help
Eliminate default vantage submit button in form-listing.php
Add this code in ACF api.php in function acf_form_head()
// allow for custom save
$post_id = apply_filters('acf_form_pre_save_post','va_after_create_listing_form', $post_id);
That's it, hope it work in your site.
Is that you want when someone visits the website that they are able to send info via the page they visits eg www.yoursite.com/listing/listing-name like probably an email or contact for more info relating to that business?
If not then you can simply add in the ACF data from the back-end i.e. dreamweaver etc onto single-listing.php and use the ACF tutorial on working with fields.
Hope this helps somewhat
Cheers
I am trying to automatically display all the custom fields of a custom post type alongside it's title and content.(Not in admin but on my actual site)
I need to be able to do this with an action hook or filter, rather than creating a template.
After scouring the web I was able to find the 'publish_{custom_post_type_name}' hook:
function my_cool_hook() {
echo get_post_meta($post->ID, 'my-custom-field-name', true);
}
add_action( 'publish_past_symposia', 'my_cool_hook' );
but it doesn't seem to do anything when I view my published custom post type on my site. Any ideas?
add_action( 'publish_past_symposia', 'my_cool_hook' );
This hook triggered only if PUBLISH post type.
YOu need to trigger the hook on web part - so...
add_filter('the_content', 'my_cool_hook');
function my_cool_hook($content){
return $content.get_post_meta(get_the_id(), 'my-custom-field-name', true);
}
now the content body filtred and your string from custom fields added.
I want to add a completely custom content type to the WordPress admin panel as per my image below. I don't believe this is called a plugin as I did a tutorial on those and they don't have an admin interface. I want to define a custom create/edit/delete screen for this content.
Is this possible?
What should I be searching for to get help on this?
I believe what you're looking for (as of Wordpress 3.0) is custom post types. There's quite a good tutorial on them here, however googling "wordpress custom post types" should provide a plethora of links.
http://codex.wordpress.org/Function_Reference/add_submenu_page is a good starting place to look. It will explain how to add new items into the menu.
Now, removing them is a different story. This function I wrote for one of my plugins removes entries from a submenu:
function cleanup_menu() {
global $submenu, $wpdb;
$new_submenu = array();
$remove = array( 'Cast Manager', 'Seating Manager', 'Download Reports', 'new report' );
foreach ($submenu['menuname'] as &$item) {
if ( ! in_array( $item[0], $remove ) ) { $new_submenu[] = $item; }
}
$submenu['menuname'] = $new_submenu;
}
So in your case, "menuname" would be changed to "Posts", I would guess. There's also a function remove_submenu_page, but there's no documentation on it and I haven't looked into it.