How do I output a database option that is an array into a get_posts array?

You could use wp_parse_id_list() to sanitize your comma seperated list of post IDs. It’s defined as: function wp_parse_id_list( $list ) { if ( !is_array($list) ) $list = preg_split(‘/[\s,]+/’, $list); return array_unique(array_map(‘absint’, $list)); } where we can see that it returns unique array values as well. Note that absint() is defined in core as abs( intval() … Read more

How to add day number and initial to my post graph?

I would go like this: A. Use the Unix timestamp as array key. $comment_counts[$date->format(‘U’)] = $query->post_count; B. Loop with key included. foreach( $comment_counts as $count_key => $count ) : Then you obtain the day number and the initial of the day from the key: // “d” means with leading zero, use “j” in place of … Read more

Generate an array of parent/child page IDs, based on parent page name

OK, so what we want to achieve is to write a function that will take a title of a page and return the array containing its ID and IDs of its children. So here’s the code: function get_page_and_its_children_ids_by_title( $page_title ) { $result = array(); $page = get_page_by_title( $page_title ); // find page with given title … Read more

merging an array to an existing array using add_filter

You are overwriting $args in add_yourself_to_some_examplehook(). Based on what you’re saying you want to achieve, you should be appending the new item instead: add_filter( ‘some_example_hook’, ‘add_yourself_to_some_examplehook’ ); function add_yourself_to_some_examplehook($args) { $args[ ‘Hello5’ ] = ‘HELL4’; // <– Note the syntax here. return $args; }

Show post only if match all categories

Here’s an updated version of your code that will get posts that have the Post Format Video and that have the same Categories as the current post in the loop. You’ll call wpse_get_video_posts_with_matching_categories() to execute the function. function wpse_get_video_posts_with_matching_categories() { $categories = get_the_category( get_the_ID() ); if ( empty ( $categories ) ) { return; } … Read more

Sort a custom post type array numerically

get_terms function will return an array of object. Each of them has term_id field which contains id of a term. Just use it instead of slug and you will have what you need: <?php $terms = get_terms(“ratios”); if ( $count($terms) > 0 ){ foreach ( $terms as $term ) { echo “<option value=”” . $term->term_id … Read more

wp_nav_menu show 1 item only

Why would you only want to display one item from a menu of many items? You can create additional menus by registering them in your functions.php file and then associating then in the Appearance -> Menus area of the WP-Admin. http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)