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

jjbte on "get_posts() not working as expected for alphabetical previous/next post query"

$
0
0

I know similar questions have been asked here, but those I found are very old and/or related to specific plugins.

I have registered a custom post type--"author_artist"--and I wish to sort the posts alphabetically by author/artist last name. I have created a custom field (_acf_alpha-name-title) to store the name in last name, first name format. I have successfully sorted my posts archive using this field. However, I am having trouble getting the single-post previous post links to work correctly.

I have set up the following query args to use with get_posts() to retrieve the previous/next posts (using the post entitled Bob Smith (Smith, Bob) as an example):

// Previous Post
$args = array(
  'post__not_in' => array(get_the_ID()),
  'posts_per_page' => 1,
  'post_type' => 'author_artist',
  'post_status' => 'publish',
  'orderby' => 'meta_value',
  'meta_key' => '_acf_alpha-name-title',
  'order' => 'DESC',
  'meta_query' => array(
    array(
      'key' => '_acf_alpha-name-title',
      'value' => 'Smith, Bob',
      'compare' => '<'
    )
  )
);

and

// Next Post
$args = array(
  'post__not_in' => array(get_the_ID()),
  'posts_per_page' => 1,
  'post_type' => 'author_artist',
  'post_status' => 'publish',
  'orderby' => 'meta_value',
  'meta_key' => '_acf_alpha-name-title',
  'order' => 'ASC',
  'meta_query' => array(
    array(
      'key' => '_acf_alpha-name-title',
      'value' => 'Smith, Bob',
      'compare' => '>'
    )
  )
);

The Next query seems to work fine, but the Previous query ignores my order designation of DESC. If I set posts_per_page to 1, I get the very first author alphabetically (e.g., Mary Ames) rather than the author immediately before Bob Smith. If I set posts_per_page to -1 (all posts), I get an array of all authors before Bob Smith and the array is sorted in ascending order.

Am I not doing this correctly? What am I missing?

One solution I found is to set posts_per_page to -1 and then use the array_keys() function to get the array keys from the resulting posts array. Then I use the max() function to get the highest key for Previous and the min() function to get the lowest key for Next. This works, but it's inefficient to fetch all posts when I just need one, and I still don't understand why my DESC order setting is being ignored.


sirflex10 on "How to create drop down options that dynamically change if a user selects one"

$
0
0

How can I create a form with a drop down list that dynamically changes and removes an option from the list each time it is selected? For example I want to run a fantasy football league.. I'd like a form that list 30 teams...each time a user completes the form and selects the team i'd like for that team to be removed from the list. Is this possible? Thank you.

dan382 on "Adding spans to Wordpress titles"

$
0
0

I want custom titles on my site (different pages have different styles depending on various factors).

To do this I simply used custom spans e.g.
<span id="custom">Recommendations</span> lorem ipsum

I was just woundering if this has any draw backs/ is frowned on by other developers. From my perspective it works fine. The only slight hickup is that I need to manually alter how it looks in my nav bar, but thats not really hard to resolve.

Am I missing anything?

simes on "list posts alphabetically in tag archive"

$
0
0

I am trying to have my archive page for tags deliver an alphabetized list of posts. I am using code suggested elsewhere in these pages thus:

function wpsf_orderby( $query ) {
    if ( is_admin() || ! $query->is_main_query() )
        return;
 // do conditional checks here and return on false.?

    if ( is_category( ) ) {
	remove_action( 'pre_get_posts', __FUNCTION__ );
	add_filter( 'posts_orderby', function() { return ' post_title ASC'; } );
	}
}

add_action( 'pre_get_posts', 'wpsf_orderby' );

But I keep getting the error

Fatal error: Call to a member function is_main_query() on a non-object
relating to the line if ( is_admin() || ! $query->is_main_query() )

Any clues? I have a parent category used in the code above, plus child categories and I also have tags assigned to each post, some of which are the same for different posts. I am using a child theme based on twentyfourteen with this code added into my functions.php file with a call to the function in tag.php, also in the child theme folder.

Shaped Pixels on "Remove Archive Title Labels error"

$
0
0

Out of like 1800 people using my Seasonal theme (and the pro one), the method I used in my functions file to remove the archive title labels is this:

add_filter( 'get_the_archive_title', function ($title) {

	if ( is_category() ) {
		$title = single_cat_title( '', false );
	} elseif ( is_tag() ) {
		$title = single_tag_title( '', false );
	} elseif ( is_year() ) {
		$title = get_the_date( '', false );
	} elseif ( is_month() ) {
		$title = get_the_date( '', false );
	} elseif ( is_day() ) {
		$title = get_the_date( '', false );
	} elseif ( is_post_type_archive() ) {
		$title = post_type_archive_title( '', false );
	} elseif ( is_author() ) {
		$title = '<span class="vcard">' . get_the_author() . '</span>' ;
	}
	return $title;
});

I've had 2 people, one using the free Seasonal theme and one using the pro version, both versions use the same filter. But what is odd is that only 2 people out of the 1800 are getting this kind of error:

Parse error: syntax error, unexpected T_FUNCTION in /home/content/65/10216865/html/wp-content/themes/seasonal/inc/extras.php on line 209

I got that from a support question on my free Seasonal theme.

Line 209 for both people is the first line of add_filter(....etc.

As far as I know, the code I have is the correct method. Long story short, I do not want the title labels to show for any of the archives, as they are labeled by default in the core.

Any idea why only a couple people got that error?

corykennedy on "remove page views"

$
0
0

how do i remove the page views on my posts? I've tried everything! help!

kitchin on "Adding Screen Options tab to WP_List_Table"

$
0
0

If you're using WP_List_Table you can get the Screen Options tab working pretty easily. It's the same as the tab on the right in the standard admin page for Posts.

The sample plugin Custom List Table Example at https://wordpress.org/plugins/custom-list-table-example/ can be modded slightly to get a Screen Options tab with checkboxes for the columns automatically shown and handled. Adding more fields to the tab takes a little more work. It's all about timing the hooks right.

I uploaded to Github a new sample plugin that builds on Custom List Table Example. It's called Custom List Table Screen Options Example, https://github.com/kitchin/custom-list-table-screen-options-example

Instead of modding the old plugin and doing a simple example of column checkboxes, I made it so my plugin requires the other plugin, and adds four more examples to the one in that plugin:

1. Using hooks at the right time, WP shows Screen Options for columns automatically.

2. Add 'per_page' to the Screen Options. WP has automatic code for this as well.

3. Add a single custom option to the Screen Options. WP has less code for this.

4. Add multiple custom options to the Screen Options. Not much harder.

The existing online tutorials I found were missing a few salient details:

* Most important: in the hook for validating updates, set-screen-option, pass the $value back if your plugin does not recognize the $option ! It's probably for another plugin! (You probably loaded your hook for all admin, since you must hook early, when most of the globals are not yet set up. Parsing $_GET would be the only way to avoid that. But it's not necessary to do so. Just look at the $option and leave it alone if it's not yours.)

* The 'per_page' option is special and has built-in handling code in WP. Custom options require more code. It turns out add_screen_option() is not that helpful. It just stores data for you to use, but you need the data before you can store it.

* The concept is: you have to hook before screen is set up, and then again before the page starts to render. Rendering the list table itself fires on a later hook, too late for this Screen Options stuff.

* You don't need to modify anything about your new WP_List_Table(...) code. You don't even need to use a screen parameter.

* Finally, improvements are coming for WP_List_Table in WP 4.3. Mobile will get better, and there's an idea of a primary column. It does not affect this plugin, by my testing.

* Side note, the core work on WP_List_table may lead WP to remove the @private declaration in the documentation. Some plugin devs make a copy of class-wp-list-table.php because of that declaration. Well, now we may need to copy the old style rules too, because th/td are changing, as well as a few css classes.

funcolors on "Dreaded Cookies Error"

$
0
0

Can't believe it -- no one seems to know how to fix this.

Posting on this board, desperate for a solution.

I've Googled and tried EVERY SINGLE fix suggested going back several years. I am getting this error message: ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.

Cookies ARE enabled on ALL my browsers. I've cleared cache several times. Switched themes, etc.

I know someone coding computer genius out there knows how to fix this.

Thank you in advance.
Lori


gqman on "/wp-admin/js/new/byte Hack??"

$
0
0

I just did a new install of wordpress 7 hours ago and apparently while I was sleeping someone uploaded all new wordpress files for wp-admin, wp-include. They also added this folder in the /wp-admin/js/new/byte. All the .php is open source. Some file is updating the hits.txt in this folder, it looks like it's trying to phish a yahoo email login. and send things to:
lekanmentiro2015@gmail.com
and/or sheditools@yahoo.com
It also looks like there's a backdoor that creates login.txt.

Is this something new???

jmabluez79 on "Contact Form 7"

$
0
0

I'm trying to create a form using check boxes. I'd like to have one set of checkboxes go vertical and another set align horizontally. How can I do this?

I know I can set things to "block" to align vertical but that makes everything vertical.

How do I target a specific set of check boxes in CSS?

redknite on "linking custom post types"

$
0
0

I'm trying to create an events site. the site will have 1 event a year. I would like the site to load, for example, http://www.eventsite.com/2015 and this would be the home page to load the 2015 event. I have created a custom post type for event, speakers, venue, and sponsors.

The problem i'm having is tying the CPTs together. Ie when someone is looking at the 2015 event they only see the speakers, venue and sponsors for that event.

http://www.eventsite.com/2015/speakers would load the custom post types archive page for speakers in the 2015 event.

http://www.eventsite.com/2016/speakers would load the custom post types archive page for speakers in the 2016 event

http://www.eventsite.com/2015/speakers/jon-walker would load the custom post type single page for the speaker jon walker in the 2015 event.

http://www.eventsite.com/2016/speakers/jon-walker would load the custom post type single page for the speaker jon walker in the 2016 event. who may or may not be the same person so it would have to be a different speaker post.

sqzr on "Glyphicons Dont Show in WordPress Plugin Only"

$
0
0

Hello

I have a very simple WordPress plugin that shows a menu/admin page. The page contains Glyphicons - Font Awesome.

These glyphicons are never showing. I cannot figure out why because I know the font-awesome css file is being loaded correctly and I know that the admin pages HTML works fine outside of a wordpress plugin and shows the Glyphs.

What could possibly be going wrong?

<?php
/**
*  Plugin Name: TEST Use FA Icons
*  Plugin URI:
*  Description: Test Development Plugin
*  Version: 1.0.0
*  Author:
*  Author URI:
*  License: GPL2
*/

class TEST_Use_FA_Icons_Admin
{

	public function __construct() {
		add_action('admin_menu', array($this, 'admin_menu'));
	}

	public function admin_menu() {

		wp_enqueue_style( "font-awesome", plugin_dir_url( __FILE__ ) . 'css/font-awesome.min.css', array(), false, 'all' );

		add_menu_page('TEST_DEV', 'TEST_DEV', 'administrator', 'TEST_DEV_SLUG',
					array($this, 'show_TEST_page'),
					plugins_url('images/help.png', __FILE__));
	}

	public function show_TEST_page() {
		?>
		<div class="wrap">
			<div class="container">
				<div class="col-md-12">
						<h1>Test</h1>

						<i class="fa fa-camera-retro fa-lg"></i> fa-lg
						<i class="fa fa-camera-retro fa-2x"></i> fa-2x
						<i class="fa fa-camera-retro fa-3x"></i> fa-3x
						<i class="fa fa-camera-retro fa-4x"></i> fa-4x
						<i class="fa fa-camera-retro fa-5x"></i> fa-5x
				</div>
			</div>
		</div>
		<?php
	}
}

$test_TEST_Use_FA_Icons_Admin_admin = new TEST_Use_FA_Icons_Admin();

?>

danielledyball on "Need to resize the featured image"

$
0
0

I am trying to change the size of the featured image so that it's full size will span the width of the post excerpt and will be about 300px high.

You can see the image I'm trying to make bigger on the second post here: http://www.thelandgeek.com/start/podcast/

I want to create featured images for all the posts that are the same size and fill that area.

Any help would be greatly appreciated!!

Thanks:-)

popileguizamon on "Qtranslate X - Erase text, leave flag."

$
0
0

Hi fellows! I've just installed Qtranslate X and it works awesome! I have the switcher on my main menu. But I want only the flags to be seen, I want to erase the text that says "Language" or "Idioma" (in Spanish).

Does anyone know how to do this? It would be very helpful ..

Thanks so much in advanced :)

Dave Navarro, Jr. on "Help with meta_query"

$
0
0

I am trying to get a list of all posts with specific meta-data.

I have a custom post type that is for all sports games.

I want to get all posts where the home team or away team is "Eagles", the sport is "football" and the season is "2015".

This is my code:

'meta_query' => array(
    array( 'relation'=>'OR',
           array('key'=>'home_team', 'value'=>'Eagles'),
           array('key'=>'away_team', 'value'=>'Eagles') ),
    array( 'relation'=>'AND',
           array('key'=>'season', 'value'=>'2015'),
           array('key'=>'sport', 'value'=>'Football') )
  )

All I get are the home team posts for the Eagles, none of the away posts. If I switch the order of 'home_team' and 'away_team', I get the away posts and none of the home posts.

Meta queries confuse the heck out of me.

Can someone tell me what I'm doing wrong?


bschigel on "footer issues"

$
0
0

I would like to make a custom footer, my page is white but I want a grey box as a footer with links inside the box(quick links, etc) I've been searching and I can't find any answers.
Any help would be appreciated!

hairminerals.com

ckrets on "Recent Comments in sidebar no longer"

$
0
0

I'm not sure if I posted this in the right section, just because the code that I was using was FROM a plugin,...sorry if I should have posted this elsewhere!

So I upgraded my WordPress to the newest version. I was using the following code with no issues before updating to 4.2.4:

<?php
$number=5; // number of recent comments desired
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number");
?>
<ul id="recentcomments">
<h2>Recent Comments</h2>
<?php
if ( $comments ) : foreach ( (array) $comments as $comment) :
echo  '<li class="recentcomments">' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. get_comment_link($comment->comment_ID) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
endforeach; endif;?></ul>

Which I got from here. After updating WordPress, I keep getting the following error message in my sidebar (and the error message comes up in place of my sidebar):

Parse error: syntax error, unexpected T_VARIABLE in "sidebar.php" on line 1

When I remove the code from my sidebar, my sidebar shows fine. Is there any other manual PHP code I can use that will give me the same result as the one above?

Scott on "WooCommerce Storefront - move cart out of nav bar and move search field"

$
0
0

Hi, I've installed a child theme (Deli) that i'm heavily modifying. I'm experienced with php, html and css, but not so much with Wordpress.

Just wondering how I can move the code for the shopping cart (I basically want to move it where the search field is now in the storefront theme) and I wish to move the search field down below the navigation. Looking at header.php I can see an action;

<?php
			/**
			 * @hooked storefront_skip_links - 0
			 * @hooked storefront_social_icons - 10
			 * @hooked storefront_site_branding - 20
			 * @hooked storefront_secondary_navigation - 30
			 * @hooked storefront_product_search - 40
			 * @hooked storefront_primary_navigation - 50
			 * @hooked storefront_header_cart - 60
			 */
			do_action( 'storefront_header' ); ?>

Basically I want to drill down into that and re-arrange things. Any help on how to do that would be appreciated thank you.

bebarb on "Getting and setting a date range with ajax"

$
0
0

Hi Everyone. I'm a super noob to WordPress Development. I'm used to things like struts2 and Spring, but I'm trying to teach myself. What I'm trying to do is really pretty simple. I'm trying to get the value of a date input field, set that as an option in the wpdb and then echo that value out on a php to show myself it's working.

so the input field has an id of "startDate" right. Here's my jquery in relation to the field (this is loaded in document.ready(function(){}):

jQuery('#setValButton').click(function(){
		var startDate = jQuery("#startDate").val();
		alert(startDate);
		var endDate = jQuery('#endDate').val();
		jQuery.post(
				myAjax.ajaxurl,
				{
					action: 'setDateRangeAction',
					startDate: startDate,
					endDate: endDate
				},
				function(response){
					alert('Dates set!');
					jQuery('#displayDiv').html(response);
				}

		);
	});

That seems to be working right. I'm seeing the date come through as expected in the alerts. Now, here's the action itself:

function setDateRangeAction(){
		$startDate = $_POST['startDate'];
		$endDate = $_POST['endDate'];
		$result['type'] = "success";
		$result['startDate'] = $startDate;
		$result['endDate']=$endDate;

		if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
			$result = json_encode($result);
			echo "Start Date" . $startDate;

			update_option('$ATstartDate', $startDate);
			update_option('$ATendDate', $endDate);
		}
		else {
			header("Location: ".$_SERVER["HTTP_REFERER"]);
		}
		?><h1> Start date: <?php echo "is ".$startDate ?> </h1><?php
	}
?>

I don't understand why, but the last echo is showing $startDate as 0. Can anyone help me understand what is happening?

edit: When I use chrome's dev tools and see what is being sent in the request object I see the dates for POST['startDate'] but not when I try to display that as noted above in the php.

bacalao on "How to add pagination that links to next post after last page break?"

Viewing all 8245 articles
Browse latest View live




Latest Images