Tag Info

Hot answers tagged

11

I don't think there exist one, but you could create your own, wpse_empty_trash, with something like this: /** * Add a custom hook 'wpse_empty_trash' */ add_action( 'load-edit.php', function() { add_action( 'before_delete_post', function ( $post_id ) { if( 'trash' === get_post_status( $post_id ) && filter_input( ...


3

You can add to the end of theme's header.php file this: if( is_single() ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); get_template_part( '404' ); exit(); } Note that the get_template_part( '404' ) function needs 404.php file in your theme directory.


2

Whenever you add a new item to WordPress Menu ( Appearance -> Menu ) it creates a new Post of Post Type nav_menu_item and gets assigned a post meta called _menu_item_object_id with the main Post ID. For example, if I create a page called "Home" it gets assigned a Post ID of 2. Now, when I go to Menus and add the page to a menu, WordPress creates a new ...


2

the fastest way imho would be to create a custom sql statement: global $wpdb; $rows = $wpdb->query('SELECT DATE(post_date) AS date, COUNT(*) AS count FROM ' . $wpdb->posts . ' GROUP BY DATE(post_date) ORDER BY DATE(post_date)'); foreach ($rows as $row) { echo $row->date . ': ' . $row->count . '<br>'; }


2

You'll want to use WP_Query, along with the data parameters e.g. years: $years = array( 2015,2014,2013,2012 ); echo '<table>'; foreach ( $years as $year ) { $q = new WP_Query( array( 'year' => $year, 'fields' => 'ids' ) ); echo '<tr><td>'.$year.'</td><td>'. ...


2

It's showing you the first 5 posts because that's how many posts are on page 1, and you never told it how many posts per page to load, so it used the default posts per page you set under settings. You'll want to modify the get_posts call to have the posts_per_page parameter. However, I will note the following problems: get_posts doesn't cache the way ...


2

You can try the following: ! is_admin() && add_filter( 'the_content', function( $content ) { if( in_the_loop() ) // <-- Target the main loop { $prepend = 'HERE IS SOME CUSTOM TEXT'; // <-- Edit your text here $content = $prepend . $content; } return $content; }, 9 ); // <-- Choose some priority < 10 ...


1

This can be done much better with the date_query property of WP_Query class. This will get the posts before the publish date of the current post // WP_Query arguments $args = array ( 'post_type' => 'posts', 'post_status' => 'publish', 'date_query' => array( 'column' => 'post_date', ...


1

I believe you are using wordpress on your website...To add read more text u just need to use the wordpress visual editor. In this the 12 no. button is used to add read more text...Use this to add read more, there may be possibility that while adding code you are making some error..


1

Hook your form processing code to an action that runs before the page is rendered and no redirect will be necessary. function wpd_check_submission(){ if( isset( $_POST['start'] ) ) { // do your post insertion here } } add_action( 'init', 'wpd_check_submission' );


1

the_content() will output the formatted post to the web browser, if the tag is used in the post it will only display the post up to this point and will out put a "Read More" link. There are some additional flags in the method to control this behaviour. See more here. Alternatively, you may load the output of the content into a variable, if this is what ...


1

If you check the documentation for WP_Query you will notice that post_count, which you are using, returns the number of posts being displayed. That is what you see, but not what you want. found_posts returns the total number of results for the query, which is what you want. $post_count The number of posts being displayed. $found_posts ...


1

The function second parameter is the "$post_id". Ref. http://simple-fields.com/documentation/api/getting-values/simple_fields_value/ simple_fields_value("simple_field_slug", $post_id)


1

Ref. https://codex.wordpress.org/Plugin_API/Action_Reference/manage_posts_custom_column Just use the WP built in action called "manage_posts_custom_column" and in callback check for the correct column and add simple_field value with the function simple_fields_value : add_action( 'manage_posts_custom_column' , 'add_new_column_data_in_posts', 10, ...


1

There are two possible solutions: CSS edit and File edit. CSS edit(Not the best solution, but works) .post-blocks .block-info span { display: none; } It is not possible for us to write the file edit code since we don't have access to your admin panel. Install WhatTheFile plugin to find out the template that renders the code for the page and edit the ...


1

The proper argument to your tax query is terms, not term. You can see this in one of the examples in the Codex: $args = array( 'post_type' => 'post', 'tax_query' => array( array( 'taxonomy' => 'people', 'field' => 'slug', 'terms' => 'bob', ), ), ); $query = new WP_Query( ...


1

The new_to_publish hook has one argument: $post. Use that to get the post id. Here is your editted code: add_action( 'new_to_publish', 'send_notification', 1, 1 ); function send_notification( $post ){ $post_id = $post->ID;; global $wpdb; $sel2 = mysql_query("select * from gcm_users"); while($data1 = ...



Only top voted, non community-wiki answers of a minimum length are eligible