everyone!
I believe similar question have been asked already, but I had not found working solution.
The problem: I need a metabox for one exact page only.
The code I use to add a metabox is pretty simple:
function custom_meta_boxes(){
add_meta_box('custom_meta_1', 'About Us Main field','custom_meta_boxes_render',
'page','normal','high','');
}
If you look on the 4th parameter - 'page', this puts metabox on every page, so that I see it and can use it for every page I created when editing it. And I need to see it on about us page only (for example).
I`ve seen in some tutorials that instead of 'page' you can use an ID or a slug of page, but that did not work for me.
Therefore, I really need your help/advice on that.
Thanks a lot in advance.
Try to do it like this:
<?php
function custom_meta_boxes(){
global $post;
$postSlug = isset($post->slug) ? $post->slug : '';
if ($post->slug === 'about-us') {
add_meta_box(
'custom_meta_1',
'About Us Main field',
'custom_meta_boxes_render',
'page',
'normal',
'high',
''
);
}
}
And change about-us slug for that you want to add meta box.
Related
I run into a problem trying to get remove_meta_box() to work
/** remove metabox for catchkathmandu options
*/
function vpm_remove_meta_box() {
remove_meta_box( 'catchkathmandu-options', 'post', 'normal' );
remove_meta_box( 'authordiv' , 'page' , 'normal' ); //removes author
}
add_action( 'add_meta_boxes', 'vpm_remove_meta_box' );
The point is I dont want contributors and authors to edit the site design, so I wanted to remove the catchkathmandu-options. the code obviously does not reflect the condition, the codex for this function supplies the solutions for that but this code at the besic step, still isnt working - I switched back to Twenty Sixteen theme and put in the authordiv section simply to test. But still no dice.
It's added to child theme functions.php
Have I taken the wrong path and am I looking at the wrong thing entirely?
Any help appreciated!
I suppose that you are using a theme called "Catch katHmandu", and you want to remove a meta box for everyone except Admins.
Here is the usage of remove meta box:
remove_meta_box( $id, $page, $context );
And the Reference on the codex: https://codex.wordpress.org/Function_Reference/remove_meta_box
As you can read on the codex, $id is the current id of the div that you want to remove. Let's say that you want to remove "Tags box", if look for its container id you will find:
<div id="tagsdiv-post_tag" class="postbox">
...
</div>
And if you want to remove tags meta box, your code will look like this:
if (!is_admin()) :
function my_remove_meta_boxes() {
remove_meta_box('tagsdiv-post_tag', 'page', 'normal');
}
add_action( 'admin_menu', 'my_remove_meta_boxes' );
endif;
Look for the id of the meta box that you want to remove and remplace "tagdiv-post_tag" from code above with your id.
If you like my answer click the top arrow, as a coder it would mean a lot for me. Thanks!
EDIT:
As #AndrewSeabrook say, try using admin_menu hook instead of add_meta_boxes in your function.
How can I check in backend if the current post is saved/updated or not.
I need to show an metabox after the post is saved/updated.
Literally after the "Update" Button is clicked.
something like this small sketch:
function add_aftersave_metabox() {
///how to do this:
if ( $post == ?? is saved?? )
remove_meta_box('you-have-to-save', 'post', 'normal');
add_meta_box( 'post-is-saved', 'post', 'normal'); }
}
add_action('admin_head', 'add_aftersave_metabox');
Thanks for any help!
Just to make sure I understand, you don't just want to look at the blog section of your page to see if the post is posted, but you want to check it otherwise?
I am just curious as to why you may want to do so with Wordpress.
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'm trying to get Wordpress to give me a menu item to go to "latest posts." They come up on the frontpage, but once I navigate away, I want a menu item to get back there. It seems so obvious, but several hours later, the best I could do was create a custom menu with a link to "uncategorised" as a workaround. There MUST be a better way! And this way, I get a box saying "Archive of posts filed under the Uncategorized category. " Not wanted!
Create a custom page in your template directory (http://codex.wordpress.org/Pages#Page_Templates) with a custom query (check at http://codex.wordpress.org/Class_Reference/WP_Query, http://codex.wordpress.org/Function_Reference/query_posts or http://codex.wordpress.org/Template_Tags/get_posts).
Create a page in your admin and select the template you created.
Add a link to this page in your menu and you're done.
Maybe this will help: http://www.viper007bond.com/2011/09/20/code-snippet-add-a-link-to-latest-post-to-wordpress-nav-menu/
It's a filter that will 'search and replace' placeholder anchors such as '#latestpost1' with the actual url of the latest post, and thus dynamically modify the menu before it's rendered.
I'm not sure how this is for SEO, but it's a clever solution.
Give all your posts a category name. Use something generic like "News", "Articles" or "Blogs". Then, choose the category with the name you picked from the menu page under categories. Add this category link to your menu. Rename the link whatever you wish - "Blog" - for example. And, viola - all your posts will appear when people click on that link.
Try this plugin: https://de.wordpress.org/plugins/dynamic-latest-post-in-nav-menu/ works really well and code is open sourced here: https://github.com/hijiriworld/dynamic-latest-post-in-nav-menu
simple solution:
I took this guy's code: http://www.viper007bond.com/2011/09/20/code-snippet-add-a-link-to-latest-post-to-wordpress-nav-menu/
Basically what he wrote is for the menu item to link to the latest post, not posts (plural), so I just modified it and it's working:
<?php
if ( ! is_admin() ) {
// Hook in early to modify the menu
// This is before the CSS "selected" classes are calculated
add_filter( 'wp_get_nav_menu_items', 'replace_placeholder_nav_menu_item_with_latest_post', 10, 3 );
}
// Replaces a custom URL placeholder with the URL to the latest post
function replace_placeholder_nav_menu_item_with_latest_post( $items, $menu, $args ) {
// Loop through the menu items looking for placeholder(s)
foreach ( $items as $item ) {
// Is this the placeholder we're looking for?
if (!strpos(($item->url), 'latestpost'))
continue;
// if ( 'latestpost' != $item->url )
// continue;
// Get the latest post
$latestpost = get_posts( array(
'numberposts' => 1,
) );
if ( empty( $latestpost ) )
continue;
// Replace the placeholder with the real URL
$new_link = $item->url;
$new_link = substr($new_link, 0, strlen($new_link) - 12);
$item->url = $new_link;
}
// Return the modified (or maybe unmodified) menu items array
return $items;
}
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.