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

AidanG on "Passing a query between pages"

$
0
0

Hello, I'm using a search mod called Advanced Search (read more on it here: http://wpadvancedsearch.com/) and essentially what I want to do is push my search from one page - the one that the user inputs their query - to a results page that takes the query and displays the results. Below I will post my php from each page.

For searchpage.php:
Here is the php:

<?php
/*
Template Name: Search Page
*/

session_start();

$args = array();
$args['form'] = array(
                    'action' => 'http://adgo.ca/uoftclubs/search-results/');
$args['wp_query'] = array(
                        'post_type' => 'post',
                        'order' => title);
$args['fields'][] = array(
                        'type' => 'meta_key',
                        'format' => 'checkbox',
                        'label' => 'Pick Your Campus:',
                        'compare' => 'IN',
                        'meta_key' => 'campus',
                        'values' => array('utsg' => 'UTSG', 'utsc' => 'UTSC', 'utm' => 'UTM'));
$args['fields'][] = array(
                        'type' => 'search',
                        'placeholder' => 'Search for a club!');
$args['fields'][] = array(
                        'type' => 'submit');

$my_search_object = new WP_Advanced_Search($args);
?>

and the relevant html:

<div class="main-search">
        <?php $my_search_object -> the_form(); $_SESSION['searchquery'] = $my_search_object; ?>
    </div>

and then for the search-results.php:
the php and html:

<div id="search-results">
        <?php
        session_start();
        $my_search = $_SESSION['searchquery'];
        $temp_query = $wp_query;
        $wp_query = $my_search->query();
        if ( have_posts() ):
            while ( have_posts() ): the_post(); ?>
                <article>
                    <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                    <?php
                    if ($post->post_type == 'gs_field') the_field('description');
                    else the_excerpt();
                    ?>
                </article>
            <?php
            endwhile;
        else :
            echo '<p>Sorry, no clubs matched what you searched.</p>';
        endif;

        $my_search->pagination();

        $wp_query = $temp_query;
        wp_reset_query();
        ?>
    </div>

I have it set up so I created two pages in wordpress, one for each of these templates. You can see in the first page that I'm using the

$args['form'] = array(
                    'action' => 'http://adgo.ca/uoftclubs/search-results/');

to submit the form to my results page. I'm also using "$_SESSION" variables to carry "$my_search_object" to the next page.

The issue is, when I make the query and it redirects to my results page, the query itself doesn't carry over (i.e. no matter what I search every single post will appear on the results page). When I have the results page code on the same one as the query page, the search function works perfectly.

There is no doubt in my mind that there are some very poor errors made here. I'm learning so I'd appreciate being taught as you correct my mistakes.

Let me know if you need anything to help you figure out what's going wrong.


olyma on "Turning Off Open Sans for the 3.8 Dashboard"

$
0
0

I’m looking for a way to turn off the Open Sans font in the admin. I’m already using the code below to force the admin area to use a different font:

function betterfonts1() {
?>
<style type="text/css">
body {font-family: Times New Roman,Times;}
</style>
<?php
}
add_action( 'admin_head', 'betterfonts1' );

This works really well, but the Open Sans is still being called in the header. It looks like this in the header:

<link rel='stylesheet' id='open-sans-css' href='//fonts.googleapis.com/css?family=Open+Sans%3A300italic%2C400italic%2C600italic%2C300%2C400%2C600&subset=latin%2Clatin-ext&ver=3.8' type='text/css' media='all' />

For efficiency I’d like to have the call be turned off completely. I’ve tried the following bit of code:

function removeopensans() {
	wp_deregister_style( 'open-sans' );
}
add_action( 'admin_enqueue_scripts', 'removeopensans' );

And this works, but it completely removes the stylesheet so there is zero styling for all of the admin. I’ve also fiddled with the core file script-loader.php by commenting out line 634:

// $open_sans_font_url = "//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600&subset=$subsets";

Commenting out this bit of the core file does the trick. It turns off the open sans font call in the header but keeps the general admin styling. Is there a way to turn off the open sans font in the admin without fiddling with core files?

Piotr on "Using one function for two scheduled events and a form"

$
0
0

I think this is going to be difficult to explain, but I hope someone will understand. ;)

I'm building a plugin that queries data from a non-Wordpress database (a forum) and inserts it into Wordpress as custom posts. Thanks to the help of bcworkz in this topic (Thx!) I managed to create a function that does this and scheduled an event that uses this function once every hour to import any new posts created on the forum or update any edited posts. It's alsp assigning different categories to posts from different forum sections - so, I can say I'm quite happy with my first Wordpress plugin, but obviously I want it to do more. ;)

What I want to do is to use Wordpress options to change what the plugin does. I want it to do three things and I need to control some parts of them. Here's how it should work:

1. A scheduled event will import/update ALL posts from SELECTED forum sections once a day.
2. A second scheduled event will import/update a SELECTED NUMBER of latest posts from SELECTED forum sections once every hour.
3. A form will let me execute the import function to update ONE SELECTED post (let's say in case it's older than the posts which are updated every hour).

Scheduling events isn't a problem for me, neither is setting options - I already created options panel and I'm able to save options into Wordpress database. What I don't know is how to pass these options into my function depending on which event is fired. I still consider myself a newbie in PHP, so maybe the solution is simple and I just can't see it. What I think I have to do is to use variables in the WHERE clause of SQL SELECT statement of my import function. Right now it looks like this:

WHERE forums.id IN (61, 62, 63) ORDER BY topic.id DESC LIMIT 5

I think in case of my daily event it should look like this:
WHERE forums.id IN ($forum_ids) ORDER BY topic.id DESC
This will let me change or add forum sections without editing the code if my forum would have to be reorganized somehow in the future.

And in my hourly event it should look like this:
WHERE forums.id IN ($forum_ids) ORDER BY topic.id DESC $limit
So I could change the number of updated posts.

The third case is different and it's not the WHERE clause that is the biggest problem - it will be one topic.id. The problem is it appears I can't use the Setting API to execute a function. I would have to connect a form in my admin panel to my import function so that when I type in the ID and hit the submit button, the function is executed - but again, I don't know how to do it.

So in short, I need to know how to pass different number of options (one in case of the daily event, two in case of the hourly event and again one in the third case) and how to do it. Unless the whole idea is wrong, and there is a better way. I also need to know how to create the form that executes my plugins function.

I'll be grateful for any advice.

Jason Ho on "How can i add something after tag by a plugin?"

$
0
0

How can i add something after <body> tag by a plugin?

magician11 on "delayed redirect"

$
0
0

I want to display a page for a few seconds and then redirect to the homepage.

Something like..

status_header(200);
get_header();
echo('<h2>content</h2>');
get_footer();
sleep(5);
wp_safe_redirect(get_site_url());

This doesn't work because I'll get

Warning: Cannot modify header information - headers already sent by

possible solutions
Sounds like I could try and add

<meta http-equiv="refresh" content="10;url=http://www.example.php">

Apparently this is now considered bad practice?

Or do something like

ob_flush();
flush();
sleep(5);

Help? Suggestions?

Thanks.

laotse on "Set own _wpColorScheme"

$
0
0

Analysing the code I found that admin_color_scheme_picker sets the JavaScript variable _wpColorScheme apparantly to dynamically shade icons. My theme uses its own color scheme, but it may be a good idea to use this mechanism as well. So I tried to use my own function:

remove_action('admin_head', 'wp_color_scheme_settings');
add_action('admin_head', 'my_backend_color_scheme');

but apparently it is still wp_color_scheme_settings, which is executed and not my function.

Any ideas why this does not work?

Is there probably a more appropriate interface to define one's own color scheme? (I hate to modify my CSS for each new version of WP)

Thanks,
- laotse.

celloblue on "Insert stuff on categories page without it looping with post list"

$
0
0

Hi, I would like to insert an image or other item between the posts listed on categories page, with the image appearing just once after the first post listed on the page. This is in contrary to reappearing in every instance of post loops. Thanks in advance for any help or suggestions!

Tom Sketch on "Custom Post Meta not displaying when web site moved"

$
0
0

Hi there,

This is the first time I've posted in the WordPress forum. I've used wordpress for a while now and have recently ventured into creating my own custom post types and custom meta so I can have more control and not have to rely so heavily on plugins.

I've managed to set up some custom post meta which has been working fine in my local environment. The idea is the user can add more than one meta box called "slides" and add data to each slide.

The problem occurred when I moved my site to a test server to start adding content etc. The custom post meta still works as expected however the content I added in the local environment will not display. It is in the database but will not come through. Any data I put in to the 'slides' overwrites the old content and then works as expected.

I need to sort this now otherwise when it come to going live I will have a lot of content to add in all over again, losing about 3 days of work!

Here are the main highlights of the code.

add_meta_box (fairly standard):

function dynamic_add_custom_box() {
    add_meta_box('slide_content', __( 'Scrolling Page', 'scrolling_pages' ), 'slide_content_custom_box');
}
add_action( 'add_meta_boxes', 'dynamic_add_custom_box' );

The main function to pull the data into the page editor (slightly simplified!):

function slide_content_custom_box() {
    global $post;
    wp_nonce_field( plugin_basename( __FILE__ ), 'dynamicMeta_noncename' );

    ?>
    <div id="meta_inner">
    <?php

    $slide_content = get_post_meta($post->ID,'slide_content',true);
    $c = 0;
        foreach( $slide_content as $content ) {
            if ( isset( $content['image'] ) || isset( $content['text'] ) ) {

				echo '<div class="slide"><h2>' . ($c+1) . '. ' . $content['title'] . '</h2><a class="sort">|||</a>
				<div class="slideContent">
				<label for="meta-title" class="prfx-row-title">Slide Title</label>
			<span class="inputWrap">
			<input type="text" name="slide_content[' . $c . '][title]" class="text_multiple_title' . $c . '" value="' . $content['title'] . '" />
			</span>
			</div></div>';
                $c = $c +1;
            }
    }
    ?>
<span id="here"></span>
<span class="add"><?php _e('Add Slide'); ?></span>
<script type="text/javascript">
 var $ =jQuery.noConflict();
 $(document).ready(function() {
	$('.slideContent').hide();
 	var count = <?php echo $c; ?>;
    $(".add").click(function() {
	slide = count + 2;
        $('#here').append('<div class="slide"><h2>' . ($c+1) . '. ' . $content['title'] . '</h2><a class="sort">|||</a><div class="slideContent"><label for="meta-title" class="prfx-row-title">Slide Title</label><span class="inputWrap"><input type="text" name="slide_content[' . $c . '][title]" class="text_multiple_title' . $c . '" value="' . $content['title'] . '" /></span></div></div>' );
		count++;
        return false;
     });
     $(".remove").live('click', function() {
        $(this).closest('.slide').remove();
     });
});
</script>
</div>
<?php
}

Saving the data:

function dynamic_save_postdata( $post_id ) {
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
        return;
    if ( !isset( $_POST['dynamicMeta_noncename'] ) )
        return;
    if ( !wp_verify_nonce( $_POST['dynamicMeta_noncename'], plugin_basename( __FILE__ ) ) )
        return;
    $slide_content = $_POST['slide_content'];
	if ($slide_content != "") {
    	update_post_meta($post_id,'slide_content',$slide_content);
	}
}

I've been banging my head against a brick wall for a few hours now. Could it be something to do with the Nonce?

Any help would be appreciated.


eddie reader on "pronlem with get_the_category"

$
0
0

I am trying to collect tracking data with regards to blog usage. I can collect everything I want except the category the individual blog belongs to,
I have tried the following
$cats = get_the_category(', ');
but I get nothing returned. The hack is in single.php where there is the following piece of code
<?php the_category(', ') ?>
to give the linked reference to a Category on the blog page.
Anybody any ideas?
Thansk Eddie Reader

jmlmj on "disable dashboard-based search field for specific roles"

$
0
0

I would like to disable the dashboard-based search field when certain user roles are logged in. I would like to keep the search field available for the role 'admin', but not others, and I would like to know how to do this with a child theme.

Does anyone have experience with this?

Dumitru Brinzan on "Theme Customizer Color Control: Can't Remove"

$
0
0

Hi,

So I have just noticed quite a funny(not) thing with the WP_Customize_Color_Control.

Let's say I have this code:

$wp_customize->add_setting(
		'theme_color_link',
		array(
			'default' => '#26bcd7',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize,
			'theme_color_link',
			array(
				'label' => 'Main body link color',
				'section' => 'colors',
				'settings' => 'theme_color_link',
				'priority' => 2,
			)
		)
	);

When I go to Appearance > Customize, I see the default value, everything is OK. If I change the color - everything is OK.

However, if I click "Save & Publish" then I'm somewhat stuck with this CSS element in the header. Whatever I choose in the color picker, I cannot "unset" this theme_mod value.

A similar thread is this one, but this actually happens no matter if there is a defined default value or not.

Using this function (from Codex):

function generate_css( $selector, $style, $mod_name, $prefix='', $postfix='', $echo=true ) {
	$return = '';
	$mod = get_theme_mod($mod_name);
	if ( ! empty( $mod )) {
		$return = sprintf('%s { %s: %s; }
		',
			$selector,
			$style,
			$prefix.$mod.$postfix
		);
		if ( $echo ) {
			echo $return;
		}
	}
	return $return;
}

So I guess the question is: how do I stop this function from adding the CSS rules in my header, when there is no value or the value is the default one?
Having redundant inline CSS doesn't feel right.

Thanks.

johngorenfeld on "Stop Twitter from widgetizing my Oembeds"

$
0
0

So when I embed a tweet URL, the following seems to happen, if I am not mistaken:

1) The URL is replaced by the tweet, as a blockquote, in unstyled text. I want this because it fits nicely into my design.

2) A moment later, Javascript replaces the blockquote with a full-blown widget: the familiar white tweet object, with a fave button, an image, a new font, new style rules, etc.

I am interested in getting #1 but suppressing #2. I think this may have something to do with sending the "omit_script" parameter to the Twitter oembed endpoint, but I can't seem to get it to work. I have been trying to use add_query_arg to add this to the query, with no luck.

I checked the debugger and it seemed as if this transformation was being carried out by Twitter's widget.js. There is a particular load() function that seems to be doing the deed.

I was wondering if anyone might be able to help me prevent Widget.js from going off when a tweet is embedded, or to suggest another way to keep my tweet embeds plain.

Any help much appreciated.

GoodMusicInc on "Weekly popular posts"

$
0
0

Im looking to make my popular post widget on the sidebar take into account the most popular posts on a 7 day range rather than since it's been installed. How do I do that? My site is goodmusicinc.net

Here is the area of the code the developer said to change, since then he has been no help -

* @param bool $display_popular_icon - Display the popular posts icon.
* @param int $popular_icon_size - The size of the popular posts icon.
* @param int $popular_amount - The amount of popular posts to display.
* @param int $popular_chars - The number of characters to display per post.
* @param bool $display_popular_view_count - Display the popular view count.
* @param string $popular_tab_post_type - The post type to display the posts for.
*
*/
public function aaw_get_most_viewed_posts($display_popular_icon = true, $popular_icon_size = 50, $popular_amount = 5, $popular_chars = 35, $display_popular_view_count = true, $popular_tab_post_type = 'post') {
$post_views = '';
$post_title = '';
$out = '';

$args = array(
"posts_per_page" => $popular_amount,
"post_type" => $popular_tab_post_type,
"post_status" => "publish",
"meta_key"	 => "aaw_views",
//'meta_value_num' => '0',
"orderby" => "meta_value_num",
"order" => "DESC"
);

[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

bbergerrr on "Add additional post content text area"

$
0
0

Hello, does anyone know of a way to add a second content text area to the wp-admin post page? The second content area also needs to have add media buttons. Basically, I need the site to display Images, then the title / author / category, then additional content that will have additional images. I found this
http://wordpress.org/support/topic/add-an-extra-text-input-field-on-admin-post-page
But the issue of adding the media buttons was never resolved. You can see an example of how the site currently looks here
http://www.beyondyoga.com/wp2/2014/01/02/being-a-modern-yogi/
The site needs to have the image slider, then the post title / author, then the remainder of the content, but currently the image slider is added in the content. Any solution will do, but it needs to be easy for a noncoder to post. The person who is posting can barely use the shortcodes needed to get the slider to work as is... I know this can be done, because I see it on this site which is also wordpress http://thechalkboardmag.com/pure-mamas-ginger-persimmon-kelp-noodle-salad#sl=3

artcoder on "pre_option_posts_per_page filter example code not correct"

$
0
0

The code in this codex page for "pre_option_posts_per_page" filter is not correct ...
http://codex.wordpress.org/Plugin_API/Filter_Reference/pre_option_(option_name)

Because I copied the code verbatim in attempt to alter the amount of displayed posts per page for a specific category. And the code did not take effect (although there was not error in output).

Can someone who knows enough about wordpress core tell me the correct code for doing this?


Chasil on "After using wp_enqueue_style the rtl.css files are not loaded any longer"

$
0
0

Hi there,

I am searching for a solution with this problem. I've got a plugin which causes problems for user who use a rtl language pack. I found out that when I use wp_enqueue_style() to load my stylesheet wordpress behaves like it is not rtl.

Heres a part of the generated html without using wp_enqueue_style():

<html xmlns="http://www.w3.org/1999/xhtml" class="wp-toolbar"  dir="rtl" lang="fa-IR">
...
<link rel='stylesheet' href='http://www.cizero.de/wp-admin/load-styles.php?c=1&dir=rtl&load=dashicons,admin-bar,wp-admin,buttons,wp-auth-check&ver=3.8' type='text/css' media='all' />
...
<!--[if lte IE 7]>
<link rel='stylesheet' id='ie-rtl-css'  href='http://www.cizero.de/wp-admin/css/ie-rtl.min.css?ver=3.8' type='text/css' media='all' />
<![endif]-->
...

And here is a snippet when I use wp_enqueue_style():

...
<html xmlns="http://www.w3.org/1999/xhtml" class="wp-toolbar"  dir="rtl" lang="fa-IR">
...
<link rel='stylesheet' href='http://www.cizero.de/wp-admin/load-styles.php?c=1&dir=ltr&load=dashicons,admin-bar,wp-admin,buttons,wp-auth-check&ver=3.8' type='text/css' media='all' />
...
<link rel='stylesheet' id='usr-style-css'  href='http://www.cizero.de/wp-content/plugins/universal-star-rating/includes/usr_style.php?px=12&ver=3.8' type='text/css' media='all' />
...
<!--[if lte IE 7]>
<link rel='stylesheet' id='ie-css'  href='http://www.cizero.de/wp-admin/css/ie.min.css?ver=3.8' type='text/css' media='all' />
<![endif]-->
...

You can see that (for example) the IE7 part changes. And load-styles.php gets dir=ltr which is incorrect.

Something happens what causes WordPress not load the rtl files.

I google'd and testet for hours but I am not able to find my misstake.

Thanks for your help!

McShaman on "Make plugin page follow standard enqueueing procedures"

$
0
0

I am writing an administrator plugin that helps a user write some simple shortcodes. When the user clicks on a new button in the TinyMCE editor a ThickBox window appears and loads a PHP template I created with a heap of prompting fields.

If I want to access new scripts or stylesheets in this window I have to hard code them into the PHP template. I.e.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script src="./scripts/myscript.js"></script>
        <style src="./css/mystyles.css"></style>
    </head>

I would much prefer to use best practice enqueuing methods as opposed to this method.

Is there a way to make this PHP document in my plugins folder do all the normal WordPress processes (e.g. enqueue script and styles) as if it were just another page?

Arnan de Gans on "Automated update not working?"

$
0
0

I'm trying to develop a module for a premium plugin to get automated updates from my own server through the "regular" update routine.

I have the system in place, it works.
The plugin is downloaded, unzipped, put in a folder.

But on the very last step where the original (old) version is deleted and the new version needs to be put in place the thing fails because the new folder is named "download.tmp" instead of the actual plugin name.

WordPress says the update was successful and is seemingly not aware of the issue.
Nothing in the logs but a bunch of errors of failed includes (because the folder name is wrong).

Has anyone heard of this before? Any thoughts?
Thanks in advance!

johnnymorriswp on "Help Adding Filter"

$
0
0

Hi All

I am using a Plugin that inserts url links into a template. I would like the links to open in a new window. I can modify the core Plugin template to do this as follows (see last line of code below). However I know this will be lost if the Plugin updates. I would therefore like to add a filter in the functions.php file in my child theme to do this instead, but am not sure how to do it. Any advice appreciated. By the way, site is currently only on local host so no link to include.

Thanks

// Begin templating logic.
			$tpl = '<div itemscope itemtype="http://schema.org/Person" class="%%CLASS%%">%%AVATAR%% %%TITLE%% <div id="team-member-%%ID%%"  class="team-member-text" itemprop="description">%%TEXT%% %%AUTHOR%%</div></div>';
			$tpl = apply_filters( 'woothemes_our_team_item_template', $tpl, $args );

			$count = 0;
			foreach ( $query as $post ) { $count++;
				$template = $tpl;

				$css_class = apply_filters( 'woothemes_our_team_member_class', $css_class = 'team-member' );
				if ( ( is_numeric( $args['per_row'] ) && ( 0 == ( $count - 1 ) % $args['per_row'] ) ) || 1 == $count ) { $css_class .= ' first'; }
				if ( ( is_numeric( $args['per_row'] ) && ( 0 == $count % $args['per_row'] ) ) ) { $css_class .= ' last'; }

				// Add a CSS class if no image is available.
				if ( isset( $post->image ) && ( '' == $post->image ) ) {
					$css_class .= ' no-image';
				}

				setup_postdata( $post );

				$title 		= '';
				$title_name = '';

				// If we need to display the title, get the data - JOHNNYM added to line 115 target=_blank
				if ( ( get_the_title( $post ) != '' ) && true == $args['display_author'] ) {
					$title .= '<h3 itemprop="name" class="member">';

					if ( true == $args['display_url'] && '' != $post->url && apply_filters( 'woothemes_our_team_member_url', true ) ) {
						$title .= '<a href="' . esc_url( $post->url ) . '" target="_blank">' . "\n";
					}

jimii on "Want to hide-unset media-menu & set featured img tab on upload mgr"

$
0
0

I need some help to try and hide or unset the .media-menu element and to style the .media-frame-content (left side panel of media upload mgr). I'd also like to hide the set featured image meta link... ideally hiding both of these from anyone that is not an admin (update core)

I've tried a small plugin and child theme colors css file to the point of exhaustion...

Is there a simple function edit that I can put in my child function file that will hide the tab and set featured image meta link?

I user twenty ten with wp property. Thank you for any guidance.

Viewing all 8245 articles
Browse latest View live




Latest Images