wordpress: change order of publish meta box - wordpress

I'm building a site with WP and the Event Manager plugin, which adds several meta boxes. Client wants all meta boxes to be in one column. No problem there.
But the Publish meta box is like the second or third box. Way too high in the page, and above many of the Events Manager meta boxes.
I can "remove/add" the Publish meta box using the functions.php file, but no combination of $context & $priority variables move it lower in the page.
I have tried hacking the edit-form-advanced.php file in wp-admin, but there does not appear to be anything in there that controls the position of the Publish box.
I have even tried a met box order plugin but no help.
I'm sure you all agree that having the Publish meta box near the top of the form is unacceptable.
Any ideas?
I'm also posting to the Events Manager support thread, but hoping for some help here also.

After additional searching and experimentation, this code added to the functions.php file in the theme got the Events Manager boxes in the desired order...
add_filter( 'get_user_option_meta-box-order_event', 'metabox_order' );
function metabox_order( $order ) {
return array(
'normal' => join(
",",
array( // Arrange here as you desire
'event-categoriesdiv',
'em-event-when',
'em-event-where',
'em-event-attributes',
)
),
);
}

Related

Add orderby="rand" function in wpbakery Wordpress

I have a theme for an eCommerce website and my homepage is built with wpbakery. Products displayed in the homepage are not changing after refresh. All the products are in the same place. I found no option in wpbakery elements to change order by random. How can I add this functionality?
I am sure in wpbakery there is a way you can do this by selecting a random option. But if you are unable to find it check and see if this works in your case.
add_action('pre_get_posts', 'my_pre_get_posts');
function my_pre_get_posts($query) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set('orderby', 'rand');
}
}
Put the code in your function file. It will set your homepage post orderby rand. Hope it works but I advise you to follow WPbakery setting to do that.
Simple Steps to find your way in WPbakery
make sure your plugin is active
Go to the page set as your homepage and click on edit page
open the post setting in the wpbakery
Select Data setting
Choose the first option which is "Order by"
scroll down and select "Random order" and save your setting.
That should point you to the right way to set random post order in WPbakery.

Custom Plugin - Posting data from main page to another page within your plugin

I created a new custom plugin, that adds a new admin menu to show a list of events. When you click any given event, I want to send you to another page in my plugin that will then render information about this event. I can keep it simple and just use a query string parameter, so don't need to do a form POST, but I would be interested in that as well.
There are two pages:
/my-plugin/reservation-management.php
/my-plugin/reservation-management-details.php
My setup in the base page (reservation-management.php):
add_action( 'admin_menu', 'addReservationManagementMenuItem' );
function addReservationManagementMenuItem(){
add_menu_page('Reservation Management', 'Reservation Management', 'manage_options', 'reservation_management_slug', 'reservation_management_building_function','',3);
}
Inside my function to build out the first screen, I render some clickable links. To simplify:
function reservation_management_building_function(){
if(!current_user_can('manage_options')){
?>
<h2>Clickable Link</h2>
<?php echo("<a href='reservation-management-details.php?id=$id'>Event</a>"); ?>
<?php
}
}
?>
I just simplified the code, removed some loop logic, etc, but it works and renders out in a loop all of the events with a url of reservation-details.php?id=x where x is the unique post id of each event.
The thing is, this just sends me to a page not found. I even tried using things like get_admin_url() etc
I think I'm missing a fundamental step in how a custom plugin can post from one page to another all while still being within wp-admin.
How can I use an href to safely send the admin user to another admin page within my plugin directory?
Thanks!
Has the page been declared in the plugin? It sounds like you'd need to add a submenu page to your plugin as well.
Example (edited):
add_action( 'admin_menu', 'addReservationManagementMenuItem' );
function addReservationManagementMenuItem(){
add_menu_page('Reservation Management', 'Reservation Management', 'manage_options', 'reservation_management_slug', 'reservation_management_building_function','',3);
//add any relative submenu pages here
//you can have as many submenu pages as you need
//please keep in mind that add_submenu_page() requires a different set
//of parameters passed to it
//if you want the submenu page viewed, and your function exists on your
//plugin definition page
add_submenu_page('reservation-management-details.php', 'Reservation Management Details', 'Reservation Management Details', 'manage_options', 'reservation_management_details_slug');
//if you don't want your submenu page accessible in the submenu
//use null as the first parameter to remove it's inclusion from the submenu
//specify the php file used
add_submenu_page(null, 'Reservation Management Details', 'Reservation Management Details', 'manage_options', 'reservation-management-details.php');
}
In the above example, you'd be able to post to your new page in your plugin, because you've now defined it. But often times, I find that I don't want anyone being able to get to a page I've designated as '_POST' only, so my first parameter is then set to null.
Edit:
The only thing that I can't remember off the top of my head is what that POST url needs to be. Please let me know if you need assistance with that, and I'll work it out for you.
Please let me know if you have any questions.

woocommerce checkout country

Hi and thanks in advance for any help,
I need to debug the woocommerce checkout page in which some fields of the form billing are not aligned correctly for some countries.
i saw that the issue is resolved if i add a after the postcode field, the function woocommerce_form_field( $key, $args, $value = null ) adds that div if $args['clear'] is not empty and it's called in a foreach for the checkout page in the checkout/form-billing.php file.
woocommerce_form_field(...) is in woocommerce/includes/wc-template-functions.php.
The $args contains the clear attribute correctly and woocommerce_form_field returns the field with div correctly (mailed myself the data from the function), when i get to the page the div is not there and fields are not aligned. Also i noticed that if i try to echo something it doesn't appear on the page source but if i mail the data from the same form-billing.php spot the data is received correctly.
How can i make the div show correctly ? What javascript could rewrite the form and where can i edit it ?
the fields disaligns if you select United States in the country select.
Any suggestion would be appreciated
P.S.: i added some javascript that adds the div on document.onload but it feels dirty and i'm not sure it works in every case.
EDIT: rephrase, clarify
To be safe when updating woocommerce in future versions you should do the following:
Best is to replace checkout.min.js with your own modified version.
Placing this in your functions.php should load your modified script
$wp_scripts->registered[ 'wc-checkout' ]->src = get_stylesheet_directory_uri() . '/js/yourmodifiedcheckout.js';
Hope this helps, let me know if you need further help.

Wordpress - Different sidebar for each page

Client needs an website to migrate into WordPress.
In this website each page has an sidebar with different content inside it
In some page accordion comes under sidebar, in some just text and images are visible
How to implement this in WordPress?
If template has to be created, there are many page it cant be done so
Even for every page different sidebar widget is not also possible
Guide me a way to implement this
A different sidebar (widget) are can be added to each page in two steps:
Add the sidebar to the theme template using the page slug as part of the sidebar name. This ensures that the sidebar has a unique name for that page.
Register the sidebars for each page in functions.php for your theme
Add the sidebar to the theme template
In your theme template, add the following code where you want the widget area to be:
<?php
global $post;
dynamic_sidebar( 'widget_area_for_page_'.$post->post_name );
?>
Register the sidebars
In functions.php for your theme add the following block of code to register the sidebars for each page in your site. Note that it includes draft pages etc so that you can edit the widgets while still in draft mode.
function myTheme_registerWidgetAreas() {
// Grab all pages except trashed
$pages = new WP_Query(Array(
'post_type' => 'page',
'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit'),
'posts_per_page'=>-1
));
// Step through each page
while ( $pages->have_posts() ) {
$pages->the_post();
// Ignore pages with no slug
if ($pages->post->post_name == '') continue;
// Register the sidebar for the page. Note that the id has
// to match the name given in the theme template
register_sidebar( array(
'name' => $pages->post->post_name,
'id' => 'widget_area_for_page_'.$pages->post->post_name,
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
) );
}
}
add_action( 'widgets_init', 'myTheme_registerWidgetAreas' );
Hope it helps!
There's a great plugin for this:
https://wordpress.org/plugins/custom-sidebars/
Sometimes it is necessary to show different elements on the sidebars
for some posts or pages. The themes nowadays give you some areas to
put the widgets, but those areas are common for all the posts that are
using the same template. NOTE: You need to use a theme that accepts
widgets to make this plugin work.
I think this is what you're looking for.
This can be done with the https://wordpress.org/plugins/jetpack/ plugin. Once activated you can choose what widgets display on what pages:
The Widget Visibility module enables you to configure widgets to appear only on certain pages (or be hidden on certain pages) by using the Visibility panel.
Visibility is controlled by five aspects: page type, category, tag, date, and author. For example, if you wanted the Archives widget to only appear on category archives and error pages, choose “Show” from the first dropdown and then add two rules: “Page is 404 Error Page” and “Category is All Category Pages.”
Just tried custom-sidebars with the latest version of wp. Had a hard time deleting it. Database is still messy. Plugin did not work. Maybe the 'pro' version is useful, but the 'non-pro' version would not add a sidebar to the page. It was clunky and did not allow per-page sidebars. It says its not been tested with the latest wp, maybe that's the problem.
You can create custom sidebar for for each post and pages with the help of plugin. There are a few plugins which enables you to create your custom sidebar. Here in this tutorial we are using Easy Custom Sidebars. Download and install this plugin in your website and activate it.
After successfully activating the plugin go to Appearance > Sidebar Replacement
From this page give a name to your custom sidebar and click on the Create Sidebar button. After that go to the Sidebar Properties option. Here you need to select the properties where you want to replace your created custom sidebar instead of theme sidebar. You can view your available option in the drop-down menu. Select it and provide a description on the Sidebar Description field.
Now in the last step select the post or pages to add this custom sidebar. You can see all the option in the left column. You can select specific post, page, category , tag, author to add this sidebar. Just select it and click Add to sidebar option.
For better understanding you can follow this tutorial

Create a blog post from content in another post type

The Wordpress site I'm working on has a section for "News" (which is the regular blog/posts) which will be used for any news the company has to write about. Then I have a custom post type for Promotions, which has it's own page.
I want the client to be able to add his promotion content through the custom post type, which is going on the Promotions page, however I'd like this content to also be "cross posted" into the blog/news without forcing the client to write it up twice.
Is there a way to do this? Thanks.
Just a note: The reason I have the promotions as a custom type on it's own instead of just having them do it all from the blog is because I needed custom fields that would be unnecessary for any other kind of blog post.
Two options:
1) Use the Shortcode API
And in your cross-post you'd add the shortcode [crosspost id="POST-ID"]. Where POST-ID corresponds to the numeric ID of the other post (post type). Instead of ID, the title could be used, see the function get_page_by_title.
Create your own plugin for this. Add a sample shortcode from the Codex and use the function get_post to get the contents of the cross-post.
2) Use Advanced Custom Fields plugin
With it, adding meta boxes with custom fields is a breeze. And it has a Post Object field that's basically a Cross Post functionality.
You could do it a lot more simply by adding a filter to wp_insert_data(). For example, in your theme's functions.php file add the following:
add_filter('wp_insert_post_data', 'post_to_other', 99, 2);
That filter will then run anytime you add a new post. In the function post_to_other(), you look to see what type of post is being submitted. If it's a promotion, then insert a second copy as a News item.
function post_to_other($post_id, $post){
/** check $post to see what type it is, if it's a promotion */
if($post->post_type == 'promotion'){
$second_post = array(
'post_type'=> 'post',
'post_title'=> $post->post_title,
'post_name' =>$post->post_name,
'post_content'=> $post->post_content,
'post_author'=> $post->post_author,
'post_status'=> 'publish',
'tax_input'=> array('taxonomy_name'=>array('news'))
);
wp_insert_post($second_post);
}
}
I'm running out the door so I don't have time to double check the exact code but that's the basic structure of it. The tax_input bit is optional, lets you specify a category if you want. You'll probably need to tweak it a bit but that's the basics.

Resources