Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

algopro on "Personalizing Content Display using tags"

$
0
0

Hi,

We are building a large knowledge-base style website with 1000+ articles. I need guidance on content personalization and ready to pay for it.

Idea:
1. Allow tags to be added to each registered user (manually)
2. When a user logs in, he should see only those articles on index page which have the same tags as the tags in his user-profile.

Thanks in advance for helping me out.


Guido on "Metabox checkbox stays checked"

$
0
0

Hi!

I have added a checkbox to my metabox:

// get data
$event_multi_day = get_post_meta( $post->ID, 'event-multi-day', true );

// input field
<input class="checkbox" id="vsel-multi-day" type="checkbox" name="vsel-multi-day" value="1" <?php checked( $event_multi_day, 1, true ); ?> />

// save data
if ( isset( $_POST['vsel-multi-day'] ) ) {
	update_post_meta( $post_id, 'event-multi-day', sanitize_text_field( $_POST['vsel-multi-day'] ) );
}

As you can see I'm using the checked feature described here.

After pressing submit, the checkbox stays checked!

After searching the net I've added this to the update feature:

// delete value if not set
if ( !isset( $_POST['vsel-multi-day'] ) ) {
	delete_post_meta($post_id, 'event-multi-day');
}

Because solution above isn't described in codex I'm wondering whether this is the common solution for a checkbox?

Guido

maxou64 on "mysql query to add stikcy post"

$
0
0

Hello,

I wonder how to add a post as a "sticky post" with a mysql query ?
Any idea ?
Thanks

moizsahil on "mce_external_plugins is not working"

$
0
0

Tinymce external plugin hack is not working on wordpress 4.4.1.

add_filter( 'mce_external_plugins', 'microlise_add_tinymce_plugin' );
function microlise_add_tinymce_plugin( $plugin_array ) {
$plugin_array['cta_button_script'] = plugins_url( '/cta-button.js', __FILE__ );
return $plugin_array;
}

boybawang on "What is the 'stable tag' in the plugin's readme.txt?"

$
0
0

I'm about to submit my first plugin to WP, but am a bit confused by the stable tag within readme.txt. Can somebody shed some light on this?
Thanks

skunkgrunt on "My first plugin"

$
0
0

Looking for a little help with a plugin I've written.  It's fairly simple.
I need it to add a custom post type to the admin menu. This part I got. This next part is where I've gone awry using taxonomies.
When you click on the post type, I'd like it to drop down a list of four options. When you click on any of the four options, it will bring you to that categorie's posts.

Example:

Workouts
-Easy
-Medium
-Hard
-User Created

Screenshot of admin menu

I don't want any of the options that are currently in that screenshot.

The idea is to have the easy, medium, and hard be pre-populated with workouts, and obviously the User Created would be for the User to post his/her own.

I've managed to get the Workout taxonomy to appear in the admin menu. But when I click on it, it brings me to the category management page. Ok, so I tried creating some categories, but they don't show in the post editor. In addition, I'd like the normal post categories to not be available for any posts in this custom post type.

I must be missing something with the taxonomies and categories. This seems like it should be simple.

Thanks to anybody that can help.
I'll gladly post the code if it helps.

Roshy10 on "add_options_page slug not working with add_settings_section"

$
0
0

I'm trying to create an options page for my plugin, however when I use add_options_page, it creates the page, but my add_settings_section/field /register_setting don't latch onto it. I've gotten all of these examples from the wordpress/codex website, so I presume it's correct.

The submenu item settings > Roshan's functions is appearing fine, but it only contains the title and text from below. Not the form or text input.

They do however work perfectly fine if I set them to go onto page general as in the example below.
Wherever it says general below, if replaced with roshans_settings causes the settings to stop appearing (on any page).

add_action( 'admin_menu', 'roshans_custom_admin_settings' );

function roshans_custom_admin_settings() {

    add_options_page(
        'Roshan\'s Functions',
        'Roshan\'s Functions',
        'manage_options',
        'roshans_settings',
        'roshans_function_options'
    );
}

function roshans_function_options() {
    ?>
    <div class="wrap">
        <h2>My Plugin Options</h2>
        your form goes here
    </div>
    <?php
}

/*
 * Add all your sections, fields and settings during admin_init
 */

function roshans_settings_api_init() {
// Add the section to roshans_settings settings so we can add our fields to it
add_settings_section(
'roshans_setting_section',
'Menu Settings',
'roshans_setting_section_callback_function',
'general'
);

// Add the field with the names and function to use for our new settings, put it in our new section
add_settings_field(
'roshans_menu_loc',
'Menu Location',
'roshans_setting_callback_function',
'general',
'roshans_setting_section'
);

// Register our setting in the "roshans_settings" settings section
register_setting( 'general', 'roshans_menu_loc' );
}

add_action( 'admin_init', 'roshans_settings_api_init' );

/*
 * Settings section callback function
 */

function roshans_setting_section_callback_function() {
echo '<p>Settings for Roshan\'s functions</p>';
}

/*
 * Callback function for our example setting
 */

function roshans_setting_callback_function() {
$setting = esc_attr( get_option( 'roshans_menu_loc' ) );
echo "<input type='text' name='roshans_menu_loc' value='$setting' />";
}

vindicateme on "bloginfo('template_directory') no longer returning full url including domain"

$
0
0

I am having trouble with bloginfo('template_directory') and any other function that is supposed to return the url of my theme directory. It used to be that it would return a full url including domain name (ex: http://www.domain.com/wp-content/themes/themename) but now it only returns "/wp-content/themes/themename"

Normally this would actually be okay, however, I need the full URL because I am sending an html email which is rendered by my theme and I need the URL for the images.


bsteeletx on "wp_get_current_user() gets a different user"

$
0
0

I am attempting to keep users from purchasing items twice by using the following code:

$current_user = wp_get_current_user();
$email = $current_user->email;
if ( woocommerce_customer_bought_product( $email, $current_user->ID, $product->id))
   echo 'Purchased';

However, the $email variable rarely shows the user's email address, and so often PREVENTS purchases due to some other customer having already purchased the item. Is wp_get_current_user() completely broken? Is there a better command I can use to achieve the same results?

stevewilson on "Code for searching posts?"

$
0
0

Does anyone know how to acquire the code behind the search box that searches posts, or itsequivalent? To make clear what I'm looking for, I would like to loop through all posts in our website's database to find all graphics used over the years so as to eliminate all in our overstuffed library that are *not* in use, thereby to reduce storage and clutter.

Guido on "Use dateformat outside the function"

$
0
0

Hi again,

After hours of trying another issue.

I'm building a date format switch using this tutorial.

I have changed the converter to change the php-dateformat into js-dateformat:

// set datepicker date formats for europe and us
function datepicker_dateformat($output) {
	if ($output == 'j F Y' || $output == 'd/m/Y') {
		$output = 'dd-mm-yy';
	} else {
		$output = 'yy-mm-dd';
	}
	return $output;
}

Question, how do I retrieve the $output for use as dateformat in the value of my date input field?

value="<?php echo date_i18n( get_option( 'date_format' ), esc_attr( $event_date ) ); ?>"

I know I have to replace the date_format part, but what should I add here?

Guido

smartIt on "Add a slider on homepage after menu bar"

fcornia on "Tweak Gallery output keeping shortcode's ordering"

$
0
0

Ok... i spent a day searching a solution for this issue but i'm not able to put myself out of trouble.

I have integrated Flexslider2 by myself, in a custom tailored work, filtering standard gallery output. I have followed a Tiffany Brown tutorial with some customization on it regard markup output.

Everything works flawlessy, except the gallery ordering... I'm not able to output the gallery order given via shortcode, the gallery always keep the upload (ID i think) order whathever i do.

Here is the code relative to shortcode interpretation:

static $instance = 0;
    $instance++;

    // Limiting what the user can do hardcoding most short code options.
    extract(shortcode_atts(array(
            'id'         => $post->ID,
            'include'    => '',
            'exclude'    => ''
    ), $attrs));

    $id = intval($id);

    if ( !empty($include) ) {
         $params = array(
                    'include' => $include,
                    'post_status' => 'inherit',
                    'post_type' => 'attachment',
                    'post_mime_type' => 'image',
                    'order' => 'ASC',
                    'orderby' => 'menu_order');
            $_attachments = get_posts( $params );
            $attachments = array();
            foreach ( $_attachments as $key => $val ) {
                    $attachments[$val->ID] = $_attachments[$key];
            }
    } elseif ( !empty($exclude) ) {
            $params = array(
                    'post_parent' => $id,
                    'exclude' => $exclude,
                    'post_status' => 'inherit',
                    'post_type' => 'attachment',
                    'post_mime_type' => 'image',
                    'order' => 'ASC',
                    'orderby' => 'menu_order');
            $attachments = get_children( $params );
    } else {
            $params = array(
                    'post_parent' => $id,
                    'post_status' => 'inherit',
                    'post_type' => 'attachment',
                    'post_mime_type' => 'image',
                    'order' => 'ASC',
                    'orderby' => 'menu_order');
            $attachments = get_children( $params );
    }

    if ( empty($attachments) ) {
        return '';
    }

    $selector = "gallery-{$instance}";
    // markup generation from here ...>

I have also tried to change orderby parameter with others sortings, es.rand , menu_order ID (stated as default in current docs) , post__id (see in some discussions but not documented) but in my code it seems this parameter is totally ignored... i can also put an arbitrary parameter like 'whateweryouwant', and the order still don't change (and no errors of course).

The filter is necessarily working because the gallery's markup put right after the code shown is working.

Someone can suggest me what's going on here?

perthmetro on "Auto generate post title - how to include different post meta"

$
0
0

I have the following snippet that allows me to auto generate the post title. I'd like to change the $post_type of the 'post_title' => $post_type . ' Job #' . $post_id to some other post meta like post date and post author.

Thanks heaps.

function save_post_func_2134( $post_id ) {
    $post_type = 'post'; //Change your post_type here
    if ( $post_type == get_post_type ( $post_id ) ) {  //Check and update for the specific $post_type
        $my_post = array(
            'ID'           => $post_id,
            'post_title' => $post_type . ' Job #' . $post_id //Construct post_title
        );
         remove_action('save_post', 'save_post_func_2134'); //Avoid the infinite loop
        // Update the post into the database
        wp_update_post( $my_post );
    }
}
add_action( 'save_post', 'save_post_func_2134' );

perthmetro on "All my WordPress code snippets and hacks on GitHub"


wildert on "Edit a Post from pure javascript"

$
0
0

I am building a pure javascript tool and I want it to be able to make modifications to an existing post. The javascript runs inside the post, so there should be no cross origin problems. I looked at the rest api and wpcom.js but they seem to require me to know the access token, which looks like an HttpOnly cookie.

Anyone have a working example of this?

bmmtstb on "Show sth on the Sidebar and easy deactivate it"

$
0
0

Hello,
i've used PHP inside the Sidebar to show a Message.

<?php $HKS_geschlossen = TRUE; ?>
<?php if ( $HKS_geschlossen): ?>
TEXT
<?php endif ;?>

My problem now is, that I have some more People using that Site, who have to change the Value of $HKS_geschlossen. Is there a Way to create sth like a Checkbox in the Admin-Bar where people with rights can change the Value? Thats what I thought is easy to use for "non-coders". If that doesn't work, does sb. know another way to simply change a Value to display/not display a part in the sidebar?

Site is: blog.schwimm-club.de

Martin

hityr5yr on "How to popup a message after saving a widget instance in "Inactive Widgets"?"

$
0
0

Hi all!

I would highly appreciate any help on following issue:

I develop a plugin that creates multiple widget instances. I would like to popup a message with some important information to the users after saving instances in "Inactive Widgets". That message should popup only once - after the first saving and, once again, only when saving is in "Inactive Widgets".

So please, advise!

Thank you in advance!

Peter

franku on "Woocommerce Show $ Discount next to Price on Variable Products"

$
0
0

Hi,

Up until around wc 2.1 we used to be able to show under the price on both the category pages and product page "Save $xx Off RRP" with the following code in our functions.php.

Around the time of WC 2.1 this code no longer works - can someone assist me in getting it working for WC 2.5 ?

add_filter( 'woocommerce_variable_sale_price_html', 'woocommerce_custom_variable_sales_price', 10, 2 );
function woocommerce_custom_variable_sales_price( $price, $variable ) {

	$reg_price = get_post_meta( $variable->children[0], '_regular_price', true );
	$sale_price = get_post_meta( $variable->children[0], '_sale_price', true );

	$percentage = round( $reg_price - $sale_price  ,2 );

	return $price . sprintf( __(' <br /><span class="price_save">SAVE &dollar;%s', 'woocommerce' ), $percentage . ' OFF RRP</span>' );

 }

Please Help

MrG0lden on "filter allowed terms by meta"

$
0
0

Hi all, I'm trying to let specific users use specific terms by term's meta, should I edit "edit-tags.php" to apply this on taxonomy list table and specifi what terms are allowed?
I haven't found a way to make that by hooking, is there any?

Viewing all 8245 articles
Browse latest View live




Latest Images