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

Peregrine2976 on "How can I include user meta information in the resulting array of a WP_User_Quer"

0
0

I'm trying to accomplish some fairly complex custom functionality on a custom WordPress site. The client has an 'About Us' page that includes a list of all team members and their pictures. We're trying to set up the site so that all the client needs to do to add or remove a team member from the About page, would be to add or remove a site user. Basically, the About page auto-populates with WordPress users of a certain user level. I think this was a really clever idea and it's working great! Here's the code (in functions.php):

function query_team(){
    	$admin_query = new WP_User_Query(
    		array(
    			'role' => 'administrator',
    		)
    	);

    	$admins = $admin_query->get_results();

    	$editor_query = new WP_User_Query(
    		array(
    			'role' => 'editor'
    		)
    	);

    	$editors = $editor_query->get_results();

    	$author_query = new WP_User_Query(
    		array(
    			'role' => 'author'
    		)
    	);

    	$authors = $author_query->get_results();

    	$contr_query = new WP_User_Query(
    		array(
    			'role' => 'contributor'
    		)
    	);

    	$contrs = $contr_query->get_results();

    	$users = array_merge($admins, $editors, $authors, $contrs);

    	return $users;
    }

As you can see, I'm combining the array results of several WP_User_Queries, since Google informed me that was the only way to get ONLY users of a few pre-defined user groups.

Now, I've encountered a bit of a problem. The client (rightfully) wants to be able to sort the users in the order he wants. So I added some custom user meta information called 'sort_order', the idea being that you could input a number and then WordPress would sort the display order of the user list based on that number. However, the problem is that these queries don't actually GET user meta information - the 'sort_order' field isn't included in any of the results from these queries.

To top it all off, it's not enough to sort the users by the meta information when we make the query; we need to sort them AFTER the arrays have been merged (because an Administrator might have a lower sort_order than an author, for example). So I need a way to include the user meta information in the array that WP_User_Query spits out, merge all the arrays, and then sort that final array using the user meta info.

TL;DR: how can I include user meta information in the resulting array of a WP_User_Query?

Thanks in advance for any assistance!


easyp on "function override"

0
0

I'd like to override a function in woocommerce, specifically -
woocommerce/includes/wc-cart-functions.php (the wc_cart_totals_order_total_html function).

I could edit the function directly (it outputs html that needs to be changed), but I'd prefer not to as I'll lose changes on updates.

I'm sure it's a common thing, I'm just not quite sure how to go about doing that. If I copy the function to functions.php in my theme, I get an error about re-declaring the function.

thanks.

aaronjheinen on "Best solution for external data API"

0
0

I have an external datasource for a few post_types that need their data to be pulled in externally. Mostly for "quality control" purposes for the Admin. I'm bringing in the data fine, I'm just wondering the best practices for integrating it into the WordPress Admin Panel.

Ideally I would have an "Update from Data Source" button on the post type, which when clicked, would make an ajax call to an API page on WordPress telling it to update that post from the external datasource.

The only way I can think of is to have a custom "API" page that would handle the query vars since I need to use WordPress's hooks to update the data.

Is there a better way to do something like this? Or is there a way to have the WordPress helper functions loaded from an update.php file I create?

Batyu-vitez on "sanitize_title_with_dashes does remove accented chars"

0
0

The Codex says sanitize_title_with_dashes doesn't repleace accented characters, but it does.
I removed this filter and worked. But I would like to use this filter but I need to keep accented characters. Do you have any idea?

MFSAM on "Show authors by post count within so many days"

0
0

Hi,

I am using the below code to gather a list of authors that have NOT had a post (of any post types) published within the last 60 days.

<?php
$args = array(
	'role' => 'contributor',
);
$blogusers = get_users( $args ); ?>
<div class="opinionators" class="cf">
	<div class="title m-all t-all d-all">More than 60 days inactive</div>
	<?php foreach ( $blogusers as $user ) {
	//echo "<pre>"; print_r($user); echo "</pre>";
	$argsone = array(
		'date_query' => array(
			//set date ranges with strings!
				'after' => '60 days ago',
				'before' => 'tomorrow',
				//allow exact matches to be returned
				'inclusive' => true,
			),
			'author' => $user->data->ID,
		        'posts_per_page' => -1,
			'post_type' => 'any'
	);
	$twomonthposting = new WP_Query($argsone);
	$twomonth_post_count = $twomonthposting->found_posts;
	 $argstwo = array(
			'author' => $user->data->ID,
			'posts_per_page' => -1,
			'post_type' => 'any'
	);
	$postingsone = new WP_Query($argstwo);
	$post_countone = $postingsone->found_posts;
	if ($twomonth_post_count == 0 && $post_countone > 3) { ?>
DO STUFF
<?php } wp_reset_query(); } ?>

I once had 50 contributors and this worked - now that I have 122 contributors it breaks before the footer.

I wonder if someone wouldn't mind scanning their expert eye over this code and seeing if I'm doing something wrong or missing something? FYI the webpage is Old Writers of Roobla.

Thank you for any help you can offer.

dune1982 on "How do I add a filter for a function in the functions.php"

0
0

Hello Guys,
hope someone can help me.
in the file class-product-cat-list-walker.php from woocommerce there is the function:

public function start_lvl( &$output, $depth = 0, $args = array() ) {
		if ( 'list' != $args['style'] )
			return;

		$indent = str_repeat("\t", $depth);
		$output .= "$indent<ul class='children'>\n";
	}

I would like to have a filter or action in the functions.php of my theme to change the line $output .= "$indent<ul class='children'>\n"; into $output .= "$indent<ul class='children' style='padding-left: 15px;'>\n";

Is there a way to do this? a custom filter or action?
thanks for help

Insomnia88 on "translation in functions.php"

0
0

Hi, I already asked this question in a plugin forum but it seems that the problem is more of wordpress nature.

You can re-read it here: https://wordpress.org/support/topic/no-functionality-in-functionsphp?replies=3#post-6748729

--------------------------------

I am trying to use _e() or __() for text translations inside the functions.php. For example for the wp_localize_script(). But I am not getting any translated strings. wp_localize_script() returns undefined in my linked script and custom functions return only the source text, not the translated one. When I hardcode strings there, they will be returned correctly.

wp_enqueue_script( 'my-script', get_template_directory_uri() . '/js/script.js', array( 'jquery' ), null, true );
wp_localize_script('my-script', 'translate', array(
            'not_required'  => __('not required', 'bla')
));

What am I doing wrong?

kpalmer@rochester.rr.com on "Attacks from China"

0
0

A web site that I manage has dozens of attempts to enter enter the site as administrator. We have been lucky that nobody has succeeded in hacking the site yet because of Word Fence blocking the entrance. I change the passwords every week or so to long passwords that contain 20 characters. Do others have this problem? It is a small site at http://www.ovationrealtygroup.com


Boiken on "Private Posts Count on Post Categories and result on searchbar?"

0
0

Im trying to use the WP to post private posts,so that only the user itself and the admin can view this post.
But i want this private posts to be counted on their specific category because by default they are not counted.

I also want to make possible to search for a private post on the search bar.

How can i do this ?

Thank you :)

jDuncanPark on "Sort Media Custom Tags"

0
0

I have uploaded roughly 45 PDF files into my Media Library. I am able to apply custom tags, categories and taxonomy to each file. I have two Pages, a Home Page and an Announcements page. The Announcements page will have all 45 pdf files. I want my homepage to always display the 5 most recent pdf files based on a date that i set in the tag/category/taxonomy.
Is this possible?

Can i just write some kind of code in page.php that says

<?php
if ( is_page('home') ) {
*code to pull 5 most recent media PDF here pulled and sorted by custom date tag*
}
?>

Thanks for any input

FaresNB on "How to add enable/disable radio option for any plugin in its option page?"

0
0

Hi,

I have been searching a lot for the right way to add enable/disable radio option for any plugin in its option page.

I am coding a site-specific plugins,very simple ones, and I want that option to be there to use it instead of deactivating the plugin.

Thanks!

FaresNB on "How to add editor access for a site-specific plugin option page?"

0
0

Hi,

Again, I would really appreciate your guidance to the right way of giving the editors the access to a site-specific plugin option page.

I have read many articles, tried a lot for several days, couldn't do it :(

Here is the plugin code:

<?php
/*
Plugin Name: A1 Important News
Description: This plugin adds Important News under the header nav in all pages
Author: FaresNB
Version: 0.9
*/

class A1ImportantNews {

	function A1ImportantNews() {
		// Initialise plugin
		add_action( 'admin_init', array( &$this, 'admin_init' ) );
		add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
		                add_action( 'A1ImportantNews', array( &$this, 'imnews' ) );
	}

	function admin_init() {
		register_setting( 'a1-important-news', 'a1_imnews_prefix', 'trim' );
		register_setting( 'a1-important-news', 'a1_imnews_title', 'trim' );
		register_setting( 'a1-important-news', 'a1_imnews_link', 'trim' );
	}
		function admin_menu() {
				add_submenu_page( 'index.php', 'خبر هام', '<b>خبر هام</b>', 'moderate_comments', __FILE__, array( &$this, 'options_panel' ) );
	}

	function imnews() {
			echo '<div id="imnews">';
			echo $meta = get_option( 'a1_imnews_prefix', '' );
			echo ' <a href="';
			echo $text = get_option( 'a1_imnews_link', '' );
			echo '">';
			$text = get_option( 'a1_imnews_title', '' );
						$text = convert_smilies( $text );
			$text = do_shortcode( $text );

			if ( $text != '' ) {
				echo $text, "\n";
			}
			echo '</a>';
			echo '</div><br clear="both"/>';

	}

	function options_panel() {
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2>لوحة خيارات الخبر الهام</h2>
<?php if( isset($_GET['settings-updated']) ) { ?>
    <div id="message" class="updated">
        <p><strong><?php _e('Update Complete') ?></strong></p>
    </div>
<?php } ?>
<form action="options.php" method="post">
<?php settings_fields( 'a1-important-news' ); ?>
<table class="form-table">

<tr>
<th scope="row" style="text-align:right; vertical-align:top;">
<tr>
<th scope="row" style="text-align:right; vertical-align:top;">
<label for="a1_imnews_prefix">نوع الخبر (هام، عاجل ..)</label>
</th>
<td>
<textarea rows="1" cols="20" id="a1_imnews_prefix" name="a1_imnews_prefix"><?php echo esc_html( get_option( 'a1_imnews_prefix' ) ); ?></textarea><br />
</td>
</tr>

<tr>
<th scope="row" style="text-align:right; vertical-align:top;">
<label for="a1_imnews_title">عنوان الخبر</label>
</th>
<td>
<textarea rows="2" cols="100" id="a1_imnews_title" name="a1_imnews_title"><?php echo esc_html( get_option( 'a1_imnews_title' ) ); ?></textarea><br />
</td>
</tr>

<tr>
<th scope="row" style="text-align:right; vertical-align:top;">
<label for="a1_imnews_link">رابط الخبر</label>
</th>
<td>
<textarea rows="5" cols="100" id="a1_imnews_link" name="a1_imnews_link"><?php echo esc_html( get_option( 'a1_imnews_link' ) ); ?></textarea><br />
</td>
</tr>
</table>

<p class="submit">
<input type="submit" name="Submit" class="button button-primary" style="font-weight:bold;margin-right:225px" value="رووووح" />

</p>

</form>

</div>
<?php
	}
}
if ( !function_exists( 'esc_html' ) ) {
	function esc_html( $text ) {
		return wp_specialchars( $text );
	}
}
if ( !function_exists( 'esc_attr' ) ) {
	function esc_attr( $text ) {
		return attribute_escape( $text );
	}
}

//add_option( 'a1_imnews_enabled', '' );
add_option( 'a1_imnews_prefix', '' );
add_option( 'a1_imnews_title', '' );
add_option( 'a1_imnews_link', '' );

new A1ImportantNews();

Guido on "Adding the datepicker in events plugin"

0
0

Hi,

I try to add the datepicker to the date field of my plugin but I cannot make it work.

1) I enqueue scripts:

function enqueue_date_picker(){
	wp_enqueue_script( 'my_script', plugins_url( '/js/script.js' , __FILE__ ), array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker'), '1.0', true );
	wp_enqueue_style('my_style', 'http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css');
}
add_action( 'admin_enqueue_scripts', 'enqueue_date_picker' );

2) My input field:

<input class="widefat" id="date" type="text" name="date" value="<?php echo date( 'j F Y', $event_date ); ?>" />

3) Added file called script.js in folder /js with content:

$(function() {
$( "#date" ).datepicker();
})( jQuery );

I notice all scripts are loaded in head section of backend.
My .js script file is loaded in footer section.
Nothing happens when I click the date field.
So what am I doing wrong here?

Have a nice weekend!

Guido

Mentalhead on "Link to date_query results in WordPress"

0
0

I have this line of code:

$args = array(
'date_query' => array(
array(
'after' => 'January 1st, 2015',
'before' => 'February 15th, 2015',
'inclusive' => true,
),
),
);
$query = new WP_Query( $args );

This code will return all the post published between Jan 1st and Feb 15th.
My question is can I somehow create a link to the results of this query?

For example I can go to

localhost/wordpress?monthnum=1

and get all posts from January, but is there a link, or can I create custom link that will accept the parameters of my date_query, so I can display all the posts that match my query?

Basically I just want to show all posts published between specific dates on a separate page, and I want a link to that page, but I don't know if such thing is possible.

Just to be clear, I just want to know is there a link such as:

localhost/wordpress?after=January1st2015&before=February15th2015

available in WordPress so I can quickly access the query results, or is there a way to create such a link?

techaddict on "Can we set SEO meta data for SEO Plugin like WP Yoast SEO using API?"

0
0

I am creating a WP Writer kind of dashboard WP has api to post content, set/create category using API. But I am unable to find way to set SEO Meta Data using API.

In short can we set custom field using API?

Can anyone help or provide info related that?

Thanks


Guido on "Custom Product Fields"

0
0

Hi,

I have added some custom product fields to the productpage of woocommerce but I am wondering if I did it the right way or not:

woocommerce_wp_text_input( array( 'id' => 'author', 'class' => '', 'label' => __('Author') ) );
woocommerce_wp_text_input( array( 'id' => 'publisher', 'class' => '', 'label' => __('Publisher') ) );

The website is up and running, but today I noticed the id other fields start with '_'.
So '_author' and '_publisher'. Does it matter?

Guido

prophotoinsights on "Adding PHP to photogallery page"

0
0

I have a Photogallery page in my Rockford Theme which I need to add a change to http://www.plantphoto.com/image-overview/

I need to add the Image link (top right next to menu) from this Portfoliopage type page http://www.plantphoto.com/image-overview/life/

I've been told the following. . . .
you can take as example the portfolio button function defined in the config/config-custom.php file around line 540 that add using and hook a new button near the menu icon, then you will need to create your own style for that.

I've given this a go but to be honest i'm not sure if I have the correct code,if I need all of it or how to add to the http://www.plantphoto.com/image-overview/ page

Code I have copied is the following and I hope someone can instruct me in simple terms how to do the above.
Regards Simon

}

if( !function_exists('thb_back_to_portfolio_button') ) {
/**
* Add the 'back to portfolio' button to every single work page when the option is enabled
*/
function thb_back_to_portfolio_button() {
if ( thb_is_page_template('single-works.php') && thb_portfolio_get_index() != '' ) {
echo '';
_e('Images', 'thb_text_domain' );
echo '
';
}
}

if ( thb_is_logo_right() ) {
add_action( 'thb_before_nav_trigger', 'thb_back_to_portfolio_button' );
} else {
add_action( 'thb_after_nav_trigger', 'thb_back_to_portfolio_button' );
}
}

Jarod B on "How to add a unique side menu for each page section?"

0
0

Hi. I'm interested in knowing how I can get a site to have a different side menu for each page section a user is on. Here is an example of a site that uses wordpress and does it:

http://www.colts-laboratories.com/testing-services/lens-cleaners-and-cloths/

If you go on the About Us or the Testing Services page, you get a different side menu every time. I want to know how I can do that with wordpress or if there is a plugin for that? Does anyone here know how I can do that?

Jeffrey O'Doherty Labrecque on "Use PHP for display/hide html element"

0
0

Hi guys,
I want to use PHP for display or hide some div.class in a document without CSS.
Can you help me?

<?php
function detectlanguage() {
$langcode = explode(";", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$langcode = explode(",", $langcode['0']);
return $langcode['0'];
}

$language = detectlanguage();

if($language=="pt"){
display all div.pt ;}

elseif($language=="fr"){
display all div.fr ;}

elseif($language=="it"){
display all div.it ;}

elseif($language=="es"){
display all div.es ;}

else {
display all div.en ;}

?>

madladuk on "Custom post type and permalinks"

0
0

Hi all.

I have a custom post type that has a slug of /mycustompost/%author%/%post_id% which is all working however I want to be able to display a list of posts if someone browsers to /mycustompost/%author% which will then display the custom posts relevant to that author, could someone advise how I would intercept this ?

Thanks
Paul

Viewing all 8245 articles
Browse latest View live




Latest Images